I find the PCRE regex option easier to work with. Herewith a solution which
takes care of case (without changing the original text), and without regard
to spaces or other characters (including the first and last characters of
the string - which you didn't mention/identify as potential problems

You will observe the 'manufactured' the text string and that the found
'needles' are post-processed only by surrounding them with ampersands
instead of your font tags - to prove that the regex works. Trust it suits.

$RegExIn = "Singapore singapore singapore. Singapore. singapore";
$RegExPattern = "|(singapore)|i";
echo "<br>Replaced:" . preg_replace( $RegExPattern, "&$0&", $RegExIn ) .


> > for ($i=0; $i < count($keywords); $i++) {
> >     $blurb = eregi_replace(" ".$keywords[$i]." ", " <font
> > color=\"#FF0000\">".$keywords[$i]."</font> ", $blurb);
> > }
> great, thats a first success and works fast.
> There are just 2 things which fail on this function:
> 1. Problems with full stops. A word with a full stop will be ignored (e.g
> singapore. will not be found if you search for singapore)
> 2. If you search for singapore and there is a hit Singapore (notice the
> capital!) will be replaced with singapore in the text.

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to