output: this is just a <b>te</b>stbut how to work around it??
(after the first term is highlighted the second one can't be found anymore.)
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.
thanks anyway!! j
snip 8<
<?
function highlight($src_terms, $src_terms_int, $result) {
$i = 0;
while ($i < $src_terms_int) {
$result = preg_replace('/('.$src_terms[$i].')/si', '<b>'.$src_terms[$i].'</b>', $result);
$i++;
}
return $result;
}
$search = "te est"; // user input to search for $src_terms = explode(" ", $search); $src_terms_int = count($src_terms);
$result = "this is just a test"; // result from database
print highlight($src_terms, $src_terms_int, $result); ?>
output: this is just a <b>te</b>st
(after the first term is highlighted the second one can't be found anymore.)
someone has an idea how to work around this?
thanks for your effort! jonas
ps: please also let me know if you know of a website that might help, i didn't find anything useful. thanks!
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php