开发者

php preg_replace problem

$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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜