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

above code works in php 5.2.6 but not working in php 5.2.9 and get " warning,unknow modifer....." error. please help

1
  • 2
    What is in strWord? var_dump($strWord); Commented Mar 28, 2011 at 3:23

1 Answer 1

4

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);    
Sign up to request clarification or add additional context in comments.

1 Comment

@Weiqiu No worries, feel free to give me the big green tick :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.