开发者

preg-replace error

开发者 https://www.devze.com 2023-02-14 09:27 出处:网络
Can anyone find the solution for this error, $str=trim(strip_tags($str)); $str = preg_replace(\"\'<style[^>]*>.*</style>\'siU\",\'\',$str);

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


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.


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

And you should use str_replace for &nbsp;.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号