Re: highlight keywords issue
| From: | Hatem Ben | Date: | Sun, 12 Jan 2003 23:51:20 +0000 |
| Subject: | Re: highlight keywords issue | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-131374@lists.php.net to get a copy of this message | ||
I have find this very helpfull :
preg_match_all("|<[^>]+>(.*)</[^>]+>|", $haystack, $out,
PREG_SET_ORDER);
It's almost done, only if i can restrict the regexp to <a > and <img> tags
only ... :(
I need to look for "Mastering Regular Expressions" book tomorrow :D it's
really boring without good docs
----- Original Message -----
From: "Timothy Hitchens (HiTCHO)" <hitcho@php.net>
To: "'Hatem Ben'" <reflex_news@yahoo.fr>; "'PHP List'"
<php-general@lists.php.net>
Sent: Sunday, January 12, 2003 2:28 PM
Subject: RE: [PHP] highlight keywords issue
> You will need to break apart the entire document then process each area
> inside of the
> tags and to be very careful for nested tags.
>
> The simplest way around I have found to do with is to add to tags that
> have been processed
> with attributes that are ignored by the browser renderer eg... <a
> href="/page.html" done="yes">PHP</a>
> as you can see the <a href has been processed because I have added in a
> extra attribute then continue
> to process the entire page from my preg matches.
>
> Nested tags are going to be your biggest issue.
>
>
>
> Timothy Hitchens (HiTCHO)
> Open Platform Consulting
> e-mail: tim@hitcho.com.au
>
> > -----Original Message-----
> > From: Hatem Ben [mailto:reflex_news@yahoo.fr]
> > Sent: Sunday, 12 January 2003 7:24 PM
> > To: PHP List
> > Subject: [PHP] highlight keywords issue
> >
> >
> > Heya all,
> >
> > I'm trying to highlight search keywords in a string,
> > everything work expect when this keyword is inside a tag like this :
> >
> > keyword (php) :
> >
> > <a href="?go=php">php</a>
> >
> > <img src="php.gif" border=0 alt="php.net">
> >
> > will be highlighted to :
> >
> > <a href="?go=<b style="color: black; background-color:
> > #ffff66">php</b>"><b
> > style="color: black; background-color: #ffff66">php</b></a>
> >
> > <img src="<b style="color: black; background-color:
> > #ffff66">php</b>.gif" border=0 alt="<b style="color:
> > black;
> > background-color: #ffff66">php</b>.net">
> >
> > I have tryed to separate text from html, then highlight it
> > then join html/text again, but this will be very long and not
> > really usefull !
> >
> > I'm using preg_replace :
> >
> > preg_replace('|\b('.quotemeta($keyword).')\b|iU', '<b
> > style="color: black;
> > background-color: #ffff66">\\1</b>', $content);
> >
> > Any help to fix that ?
> >
> > Thanks;
> > Hatem
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >