perverse Posted July 9, 2007 Share Posted July 9, 2007 Hi everyone, i need help writing a parser to replace <!-- $word --> with <img alt="tag_$word" src="images/exe.gif" class="FCK__TemplateTag" /> and then back again. Long story short i need this to parse input from FCKeditor to replace these image tags with our template systems inbuilt tags (which are just HTML comments). The reason i'm using image tags is because i needed a "marker" in FCKeditor's HTML view to show that a tag exists there (if i just let them insert html comments, they can't see it in the HTML view of the editor - and this is a problem for our HTML illiterate support staff). i figured i'd be using preg_raplce for such a task.. but my regular expression mastery just isn't at this level yet. Thanks in advance for any help you guys can come up with! Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 9, 2007 Share Posted July 9, 2007 <?php $new_source = preg_replace('/<!--\s*(.*?)\s*-->/','<img alt="tag_$1" src="images/exe.gif" class="FCK__TemplateTag" />', $source); $original_source = preg_replace('/<img alt="tag_(.*?)" src="images\/exe.gif" class="FCK__TemplateTag" \/>/i', '<!-- $1 -->', $new_source); ?> (Edit: Typo.) Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 9, 2007 Share Posted July 9, 2007 $result = preg_replace('/<!-- (.*) -->/si', '<img alt="tag_$1" src="images/exe.gif" class="FCK__TemplateTag" />', $subject); Ahh to last! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.