To explain the question more clearly ..
I need a function that:
Takes a string, lets call it it $string, that contains plain text and HTML.
Takes another string, lets call it $hl_string, which is highlighted in $string
I did this using the following function:
=======================
$string = "<p><b>heading</b><br>This is some other text!!!!<img src=../isthere.gif</p>";
$hl_string = "is";
$replacement = "<span class=\"phighlight1\">$hl_string</span>";
$string = eregi_replace($hl_string, $replacement, $string);
This seems to work fine but because $hl_string also exists inside an HTML tag it destroys the tag and you end up with:
$string = "<p><b>heading</b><br>This <span class=\"phighlight1\">is</span> some other text!!!!<img src=../<span class=\"phighlight1\">is</span>there.gif</p>";
As you can see this stuffs things up. I was trying to another regular expression that:
- Only replaces the $hl_string between a ">" and a "<" but where there is no other "< ... >" between them.
The reg exp :
">([<>])($rep)([<>])<", ">\1\2\3<"
: does seem to work but for some reason it only replaces the last instance of the $hl_string ...
one strange thing is that if $hl_string = "[abc]" for example it will highlight the last a and the last b and the last c ... which kinda makes sense but just makes it more confusing.
Summary : A reg exp that only replaces text where it will show as text, not in HTML tags!
Thanks!!!!!