PHP 正则表达式去除特定前缀 - 轻松提取URL路径
使用正则表达式可以轻松去除指定的字符串。以下是一个示例代码,使用PHP的preg_replace函数来实现://n//n//n/$url = ///'https://yiyan.baidu.com/jdkd/xee.txt?kdjss23///'//n/$pattern = ///'/^https://////yiyan//.baidu//.com//////'//n/$replacement = ///'///'//n//n/$newUrl = preg_replace(/$pattern, /$replacement, /$url)//necho /$newUrl//n//n//n运行上述代码将输出://n//n//njdkd/xee.txt?kdjss23//n//n//n正则表达式/^https://////yiyan//.baidu//.com///将匹配以https://yiyan.baidu.com/开头的字符串,并将其替换为空字符串,从而去除该部分。
原文地址: https://www.cveoy.top/t/topic/qiqM 著作权归作者所有。请勿转载和采集!