Closed Thread Icon

Topic awaiting preservation: Search a string containing HTML-tags (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=13068" title="Pages that link to Topic awaiting preservation: Search a string containing HTML-tags (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Search a string containing HTML-tags <span class="small">(Page 1 of 1)</span>\

 
u-neek
Bipolar (III) Inmate

From: Berlin, Germany
Insane since: Jan 2001

posted posted 02-28-2004 15:47

Hi there.

I have a search string (for example $q="xml") and a string ($string) containing "xml".
I want to highlight the search string in the $string variable.

This is the way i replace the string:
$string = preg_replace("/(".$q.")/i", "<span class=\"hilite\">$1</span>", $string);

But when $string contains something like "blablablah <a href="site.xml" title="site.xml">My XML File</a> blah blah blah xml blah", everything gets messed up.

My question is, who can i manage, that everything inside "<>" is excluded?

Thanks for your help.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 02-28-2004 16:47

uh. you're asking for trouble with this.

I'd use strireplace to do the replacment - you never know what's gonna be in $q next, and you'll hate it when the regxeps breaks because of some special chars in $q.

Anyhow, I guess you could use a regexps and preg_matchreplace_callback top pull out all tags and store them in an array, and store ####aLittelTag#### in their place. Then you do whatever it is you're doing now, then you do it backwards, ie. replace all ####aLittleTag#### in a callback with the actual tags poped out of the array.

Clear?

« BackwardsOnwards »

Show Forum Drop Down Menu