Ok here is my situation... I have installed a glossary add-on on my vBulletin forum. If a term is found on the forum, it will replace the term by a link to the glossary definition.
here is the regex code used by the add-on :
$findotherterms[] = "#\b$glossaryname\b(?=\s|[.,?!;:]\s)#i";
$replacelinkterms[] = "<span class=\"glossarycrosslinkimage\"><a href=\"$glossarypath/glossary.php?do=viewglossary&term=$glossaryid\"' onmouseover=\"glossary_ajax_showTooltip('$glossarypath/glossary_crosslinking.php?do=crosslink&term=$glossaryid',this,true);return false\" onmouseout=\"glossary_ajax_hideTooltip()\"><b>$glossaryname </b></a></span>";
$replacelinkterms[] = "<a href=\"glossary.php?q=$glossaryname\">$glossaryname</a>";
$glossaryterm = preg_replace($findotherterms, $replacelinkterms, $glossaryterm, $vbulletin->options['vbglossary_crosslinking_limit']);
return $glossaryterm;
The problem is that if there is a link inside a forum post with an existing term, the add-on will create a link inside the link...
So let's say "test" is a glossary term and i have this forum post:
some forum post including <a href="http://www.test.com">test</a> link
The addon will convert it to :
some forum post including <a href="http://www.<a href="glossary.php?q=test">test</a>.com"><a href="glossary.php?q=test">test</a> link
So, how can i modify this code to NOT replace anything if the string is found inside an existing link ?