Question

<? php
    $Src = 'images/pages/clients/logos/clnt_aljareera_img.jpg';
    $pttn= '/&Src:'.$Src.'/';
    $string=preg_replace($pttn,'',$string,1);
?>

//output Error: Unknown modifier 'p' in

Was it helpful?

Solution

Your string contains a whole mess of / which would need to be escaped as \/ when using / as the regex delimiter. Instead of / as the regex delimiters, use something which won't occur in your string like ~ for example. You must choose a delimiting character which is guaranteed not to appear in $Src, however. You might be safer even with | than with ~.

$Src = 'images/pages/clients/logos/clnt_aljareera_img.jpg';
// Delimit the regular expression with ~
$pttn= '~&Src:'.$Src.'~';
$string=preg_replace($pttn,'',$string,1);

What has happened is your regex delimited by / encounters a p immediately after images/ because it thinks it has reached the closing delimiter. The next word pages is mistakenly treated as a string of regex modifiers.

PHP sees the regular expression:

/&src:images/pages

OTHER TIPS

Remove the space in your opening php-tag.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top