我有一组字符串,想要替换

/church-ceremony-venues/all/in-quezon-city/church?page=2

/church-ceremony-venues/all/in-quezon-city?page=2

我试图从这个问题的答案,但没有任何反应。

===============>>#1 票数:0 已采纳

$str = "/church-ceremony-venues/all/in-quezon-city/church?page=2";
echo preg_replace("/\/church\?/", "?", $str);

===============>>#2 票数:0

获取最后一个/之前和之后的所有字符? ,则您的新字符串中包含捕获的组$1$2

$input_lines = "/church-ceremony-venues/all/in-quezon-city/church?page=2";

echo preg_replace("/.([^\?]+)\/.+(\?.+)/", "/$1$2", $input_lines);

php live正则表达式中查看示例

  ask by nards translate from so

未解决问题?本站智能推荐: