我有一组字符串,想要替换
/church-ceremony-venues/all/in-quezon-city/church?page=2
到
/church-ceremony-venues/all/in-quezon-city?page=2
我尝试按照question的回答,但没有任何反应。
答案 0 :(得分:0)
$str = "/church-ceremony-venues/all/in-quezon-city/church?page=2";
echo preg_replace("/\/church\?/", "?", $str);
答案 1 :(得分:0)
在最后/
之前和?
之后获取所有字符,然后您的新字符串包含已捕获的论坛$1
和$2
$input_lines = "/church-ceremony-venues/all/in-quezon-city/church?page=2";
echo preg_replace("/.([^\?]+)\/.+(\?.+)/", "/$1$2", $input_lines);
的示例