I have some code (I didn't write it so don't beat me up for it 😉 ) that among other things adds a definition glossary tool tip to glossary terms. Here is the code snippet:
# Glossary terms highlight
$glossarytermquery = $DB_site->query("SELECT term, tooltip FROM " . TABLE_PREFIX . "articles_glossary");
while($glossaryrow = $DB_site->fetch_array($glossarytermquery))
{
$term = preg_quote($glossaryrow['term'], "/");
$tooltip = $glossaryrow['tooltip'];
$term_match = "/\b($glossaryrow[term])\b/i";
$replace = "<acronym style=\"cursor: help;\" title=\"$tooltip\"><u>$term</u></acronym>";
$content = preg_replace($term_match, $replace, $content);
}
This works great unless the tooltip contains the term. I.E. I have the following defined:
BC - Buoyancy Compensator
Buoyancy - The upward force exerted on an object in liquid, whether the object sinks or floats. Objects that float are positively buoyant, those that sink are negatively buoyant and those that stay where placed are neutrally buoyant.
So when this code comes by the text BC it adds the Buoyancy Compensator tooltip. It then proceeds to replace Buoyancy inside the tooltip, which doesn't really work out too well.
Regular expressions are not my thing, so I'm looking for some help. I'm sure there is a way modifiy the regular expression so that it does not replace text that is already inside an <acronym></acronym> block? Can someone tell me how to do this?
James
P.S. I've already cleaned up the code to use arrays but I thought I would just post the original.