I have a script that uses custom markup to place code for Javascript tooltips. The user enters text in a form, and has access to complex code through the use of simple tags. Entries are stored in a MySQL database. The tags work like this:
[term=test]test[/term]
[def=test]This is a test[/def]
[term][/term] is the link for the tooltip, and [def][/def] is the content of the tooltip.
The code looks like this:
$entry = ereg_replace( "[term=([-./a-zA-Z0-9!&%#?,'=:~]+)]". "([-./a-zA-Z0-9 !&%#?,'=:~]+)[/term]", "<a href=\"#\" class=\"defn\" onMouseOut=\"MM_showHideLayers('\1','','hide')\" onMouseOver=\"makeVis('\1',event);\">\2</a>", $entry);
$entry = ereg_replace ("[def=([-./a-zA-Z0-9!&%#?,'=:~]+)]". "([-./a-zA-Z0-9 !&%#?,'=:~]+)[/def]", "<div id=\"\1\" style=\"border-width: 2px; border-style: inset; border-color: black; position: absolute; background-color: $popup_bgcolor; padding: 2; layer-background-color: $popup_bgcolor; visibility: hidden; width: 177px; overflow: visible\">\2</div>", $entry);
Here's my problem. When a user edits an entry, I don't want them to see all this ugly Javascript -- I want the entry text to convert back to the custom tags. How do I do it? I've been going crazy with regex and the like, and any help would be greatly appreciated.