Re: Re: string highlight
| From: | John Nichel | Date: | Wed, 08 Jun 2005 15:32:00 +0000 |
| Subject: | Re: Re: string highlight | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-216649@lists.php.net to get a copy of this message | ||
Rory Browne wrote:
<snip>
< won't be picked up as a word boundry (\b). -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 john@kegworks.comGood catch Rory. A regex replace would work better here. $search = "body"; $find = "/\b" . $search . "\b/"; preg_replace ( $find, "<b>" . $search . "</b>", $html );I don't think so. If I'm reading your code correctly you still have the same problem, as I outlined above. There is no simple solution to this. It either involves advanced regex(more advanced than my understanding of it), or a proper parser. <?pseudo_code function highlight_html_string($needle, $haystack); $retval = ""; $i = 0; while($i < strlen($haystack)){ $str = get_text_between_certain_point_and_first_instance_of_<($i); $str = preg_replace(what john said above); $str .= get_tag_text($i); $retval .= $str; $i += strlen($str); } return $retval; ?>