want to repalce /randomword/ (wildcard) with /page-1/ so url would be replaced as http://www.example.com/randomword/page-1/fixed/index?ok=as
$url="http://www.example.com/randomword/fixed/index?ok=as";
$url= preg_replace('//(.*?)/fixed', '/randomword/page-1/fixed', $url);
not working the / confuses me when i dont know when to escape it
/is the opening delimiter the last/is the closing one. Everything inbetween is the regex. From the first link note:If the delimiter needs to be matched inside the pattern it must be escaped using a backslash. If the delimiter appears often inside the pattern, it is a good idea to choose another delimiter in order to increase readability.... so~/(.*?)/fixed~i think would resolve your issue. You also might prefer any non/over(.*?)./fixed/is constant you could juststr_replacethat by prepending the new dir on it.