Re: highlighting multi term search results
| From: | jonas_weber @ gmx . ch | Date: | Sun, 07 Sep 2003 19:03:20 +0000 |
| Subject: | Re: highlighting multi term search results | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-161923@lists.php.net to get a copy of this message | ||
Am Sonntag, 07.09.03 um 14:11 Uhr schrieb Catalin Trifu <catalin@isp-software.de>:
Here the $result is changed to '<b>te</b>st' on the first search.
Obviously on the second replace the term will not be found anymore!
yes, it's obvious.
like i said:
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?? - jns /snip/
hi, i'm working on a function that highlights search results. problem: a search input like "te est"; two terms that match one word ("test"). the mysql query matches entries like this but my function isn't able to highlight them the right way: <? 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