I recently built a search function into my homemade forum. Everything works great except for one little problem.
When the user clicks on a Topic that was returned from his/her search the words they searched for get highlighted. It worked great except for one small issue. Lets say a user searched for the keyword "Hi"
With the code I am currently using (attached below) it highlights everywhere in the message there is the text Hi, but my problem is it messes up different codes like for example: [ IMG=http://google.com/images/highfly.gif], the hi of the filename highfly.gif also gets highlighted.... Here is the code I am currently using:
$message_post = preg_replace("/$keywords/i", '<span class = "highlight">'.$keywords.'</span>', $message_post);
so the image tag becomes
[ IMG=http://google.com/images/<span class = "highlight">hi</span>ghfly.gif]
which is of course not what I want. Is there anyway I can check for this?