开发者

php preg_replace problem

开发者 https://www.devze.com 2023-02-20 08:56 出处:网络
$strSubject= preg_replace(\'/\\b\'.$strWord.\'\\b/i\', \'<b>\'.$strWord.\'</b>\', $strSubject);
$strSubject= preg_replace('/\b'.$strWord.'\b/i', '<b>'.$strWord.'</b>', $strSubject);    

above code works in php 5.2.6 but not wor开发者_如何转开发king in php 5.2.9 and get " warning,unknow modifer....." error. please help


You probably have a meta character unescaped in $strWord. Try this...

$strSubject= preg_replace('/\b'.preg_quote($strWord, '/').'\b/i', '<b>'.$strWord.'</b>', $strSubject);    

Also, you could just use this :)

$strSubject = preg_replace('/\b('.preg_quote($strWord, '/').')\b/i', '<b>$1</b>', $strSubject);    
0

精彩评论

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

关注公众号