1
<? 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

fhonics
  • 113
  • 9

2 Answers2

5

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
Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
5

Remove the space in your opening php-tag.

mboldt
  • 1,780
  • 11
  • 15
  • That almost looks like the problem (and it is a problem), but the unknown modifier is a result of `images/p` where the regex thinks it encounters its closing `/` delimiter followed by a `p`. – Michael Berkowski Oct 22 '12 at 18:30
  • You're right, the opening php-tag "only" results in a syntax error.. it just jumped right into my eye and I guess he would have needed to fix it anyways ;-) – mboldt Oct 22 '12 at 18:33
  • Really, this would cause `Parse error: syntax error, unexpected T_VARIABLE` – Michael Berkowski Oct 22 '12 at 18:33