我有以下URL:
https://comanage.example.edu/sp https://wiki.cs.example.org/sp https://intranet.math.example.edu/sp https://myapp.example.com/sp
对于这些URL,我需要定义一个函数来检测它们是否为URL,并从中替换掉https://和sp路径。基本上,我只需要主机名。例如,如下所示:
https://comanage.example.edu/sp ->comanage.example.edu https://wiki.cs.example.org/sp ->wiki.cs.example.org https://intranet.math.example.edu/sp ->intranet.math.example.edu https://myapp.example.com/sp ->myapp.example.com
对于非URL,该函数应该检测并不进行替换。如下所示:
nonurl.example.com -> ***no replacement***
请问有人能为我提供上述问题的解决方案吗?我对正则表达式的使用知识不多。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号