$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);
精彩评论