Hello,
I am writing a sort of glossary script, you know the kind linking words from a list and giving a popup with an explanation.
the important part is the regex that parses the keywords in the text.
Example ( just using bold tags to show the parsed output):
PHP Code:
$word = 'test';
$textstring = 'this is a test <a class="test" href="www.test.com">some test examples</a> and another test.';
$newword = '<b> ' . $word . '</b>;
$regex = '/\b(?!<.*?)'.trim($word).'(?![^<>]*?>)\b/siU';
preg_replace($regex, $newword, $textstring);
works fine, and the output is:
this is a
test <a class="test" href="www.test.com">some
test examples</a> and another
test.
Up to here everything is OK.
--------------
Now what I am trying todo, is exclude the links completely, not only inside the anchor tag, but also inbetween (the innerHTML of the anchor).
To explain, I want the output to be:
this is a
test <a class="test" href="www.test.com">some test examples</a> and another
test.
(the text : "some test examples" not being parsed.)
I have tried nearly everything.
like
$regex = '/\b(?!<a.*?)|(?!<.*?)'.trim($word).'(?![^<>]*?>)|(?![^<>]*?</a>)\b/siU';
but oviously it doesnt work
Anybody got any ideas to put me in the right direction?
Help would be very appreciated.
Luc