سؤال

I have a set of string and want to replace

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

to

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

I try to follow answer from this question but nothing happens.

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

get all characters before the last / and after the ?, then you have your new string with the captured group $1 and $2

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

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

look example at php live regex

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top