简体   繁体   English

在PHP中使用REGEX在URL中添加端口号或从URL中删除端口号

[英]Add / remove a port number to/from a URL with REGEX in PHP

I've searched but was unable to find an existing regex function. 我已经搜索过,但是找不到现有的正则表达式函数。 Has anybody done this before? 有人做过吗?

I wish to add a port number, or remove a potantially existing one from a url in php. 我希望添加端口号,或从php中的网址中删除一个可能存在的端口号。 To use in some functions which translate a given url to the secure one, unsecure one, etc. 在某些将给定网址转换为安全网址,不安全网址等的函数中使用。

Now I need a second SSL secured site on the server so I need to dynamically add a port number while converting http to https, and remove any port number while converting from https to http. 现在,我在服务器上需要第二个受SSL保护的站点,因此我需要在将http转换为https时动态添加端口号,并在从https转换为http时删除所有端口号。

Thanks, Duck 谢谢,鸭子

您可以使用内置的parse_url函数代替正则表达式来分解并重新组合URL以符合您的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM