Re: Re: highlighting multi term search results

From: Date: Mon, 08 Sep 2003 02:21:17 +0000
Subject: Re: Re: highlighting multi term search results
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-161947@lists.php.net to get a copy of this message
On Mon, 8 Sep 2003 00:11:09 +0200, Jonas_weber @ Gmx . Ch <jonas_weber@gmx.ch> wrote:
Am Sonntag, 07.09.03 um 21:17 Uhr schrieb John W. Holmes:
output: this is just a <b>te</b>st (after the first term is highlighted the second one can't be found anymore.)
but how to work around it??
Highlight the longest words first?
I don't think that would change anything. A search for "te est" then highlights "test" into "t<b>est</b>" and "te" can't be found anymore.
Why not just allow for bold tags in the search term? What I mean is, I think you can get the results you want by allowing any number of open or close bold tags between each letter of the search term. <?php function highlight($src_terms, $src_terms_int, $result) { $i = 0; while ($i < $src_terms_int) { $termWithOptionalBold = preg_replace('/(.)/', '(<\/?b>) *\1',$src_terms[$i]); $result = preg_replace('/(<\/?b>)*('.$termWithOptionalBold.')(<\/?b>) */si', '<b>\2</b>', $result); $i++; } return $result; } ?> -- Lee O'Mara

« previous php.general (#161947) next »