0

Can anyone find the solution for this error,

     $str=  trim(strip_tags($str));

$str = preg_replace("'<style[^>]*>.*</style>'siU",'',$str);

    $patterns = array();
$patterns[0] = '&nbsp; ';
$patterns[1] = ' &nbsp;';
$patterns[2] = '&nbsp;';
$replacements = array();
$replacements[0] = '';
$replacements[1] = '';
$replacements[2] = ' ';

$str    =   preg_replace($patterns, $replacements, $str);

It showing this error.

Message: preg_replace() [function.preg-replace]: No ending delimiter '&' found

-Arun

Arun SS
  • 1,791
  • 8
  • 29
  • 48

2 Answers2

0

You have the anwser in the error code, regex needs delimiters to work.

And you should use str_replace for &nbsp;.

soju
  • 25,111
  • 3
  • 68
  • 70
0

The first character in your pattern is interpreted as a delimiter and right now PHP thinks you want to use & as a delimiter. In your first regex, the delimiter was ', BTW. I guess what you really want is not '&nbsp;', but '/&nbsp;/' (e.g. for pattern 2), now / is the delimiter (it is not part of the regex itself). BTW, your first regex seems not correct either, it should probably be

'<style[^>]*>[^<]*</style>'

Otherwise the regex could match the first tag and the very last tag of the whole document.

Mecki
  • 125,244
  • 33
  • 244
  • 253