Re: full text search and how to underline keyword in results
| From: | DL Neil | Date: | Sun, 25 Aug 2002 19:01:13 +0000 |
| Subject: | Re: full text search and how to underline keyword in results | ||
| References: | 1 2 3 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-21356@lists.php.net to get a copy of this message | ||
andy,
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
earlier!).
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 ) .
"~";
Regards,
=dn
> > 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.