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.
i thought so too (but i had no idea how to code it); this must be a solution.
i've tested your function like this:
<?
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;
}
$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); ?>
but it didn't highlight anything.
btw, the bold tag in this example is used to simplify it and stands for something like <span class="highlight"></span> what makes it even trickier, i guess.
thanks for your help! jns
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php