regex for dynamic highlighting in search results...need help
| From: | hopeless at funkaspuck dot com | Date: | Thu, 24 May 2001 06:33:24 +0000 |
| Subject: | regex for dynamic highlighting in search results...need help | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-54170@lists.php.net to get a copy of this message | ||
Forwarded to the list for suggestions...my regex is pretty rusty...
----------------------
I've got a string full of HTML, and I'd like to highlight specific words in
the text by surrounding it with <span class="highlight"></span> tags.
That's
pretty simple:
$strIn = eregi_replace("([^a-z'-])($highlight)([^a-z'-])", "\\1<span
class=\"highlight\">\\2</span>\\3", $strIn);
I gets difficult when I want to exclude any instances of the word that
happen to be within an HTML tag. Otherwise I could end up with <a
href="http://site.com/<span
class="highlight">highlight</span>/default.htm">, for example, and
that's no
good.
The following regex is the closest I've gotten (it's just the previous one
plus another subexpression), but it doesn't match anything at all. It seems
like it should work to me, though:
$strIn = eregi_replace("([^a-z'-])($highlight)([^a-z'-])([^<>]*>)^",
"\\1<span class=\"highlight\">\\2</span>\\3", $strIn);
If any regex-wizzes could help me out with this one, I'd be extra grateful.
thanks,
-josh
* [ www: endquote.com ] [ icq: 940141 ] [ aim: endquote ]