PHP 正则表达式去除 URL 前缀 - 保留路径和参数
您可以使用以下正则表达式来去除字符串中的'https://yiyan.baidu.com/'部分:
$str = 'https://yiyan.baidu.com:8484/jdkd/xee.txt?kdjss23';
$pattern = '/https://yiyan.baidu.com/(.*)/';
$replacement = '$1';
$result = preg_replace($pattern, $replacement, $str);
echo $result;
输出结果为:
jdkd/xee.txt?kdjss23
这样就可以将字符串中的'https://yiyan.baidu.com/'部分去除,只保留'jdkd/xee.txt?kdjss23'部分。
原文地址: https://www.cveoy.top/t/topic/qiqN 著作权归作者所有。请勿转载和采集!