You are here: Re: [PHP] Re: string highlight « PHP « IT news, forums, messages
Re: [PHP] Re: string highlight

Posted by Rory Browne on 06/08/05 22:37

On 6/8/05, John Nichel <john@kegworks.com> wrote:
> Rory Browne wrote:
> <snip>
> >>Good 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;
> > ?>
>
> < won't be picked up as a word boundry (\b).
Aparently it will.

[rory@mybox tmp]$ cat /tmp/test.php
<?php

$str = "<html><body>Highlight the body of the text</body></html>";

echo preg_replace("/\bbody\b/", "<b>body</b>", $str);

?>
[rory@mybox tmp]$ php -q /tmp/test.php
<html><<b>body</b>>Highlight the <b>body</b> of the text</<b>body</b>></html>



>
> --
> John C. Nichel
> ÜberGeek
> KegWorks.com
> 716.856.9675
> john@kegworks.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация