Re: marking words bold

From: Date: Wed, 11 May 2005 16:43:24 +0000
Subject: Re: marking words bold
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-214952@lists.php.net to get a copy of this message
Merlin wrote:
Hi there, I am trying to mark words inside a sentence bold. Problem is, if there is an overlap it does not work anymore. I am using this code: $t = str_replace($word, "<b>$word</b>", $text); For eample: Mark those words bold: adventure in singapore Text: My adventure flying to singapore The problem lays in the word "in". The code I use does produce following: <b>s<b>in</b>gapore</b> which of course does not work properly. Does anybody have a good sugestion on how to improve this?`
use preg_replace('/\b'.preg_quote($word).'\b/', '<b>'.$word.'</b>', ..); \b is word boundary

« previous php.general (#214952) next »