Jump to content

Help with preg_replace and HTML comments


perverse

Recommended Posts

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! :D

Link to comment
https://forums.phpfreaks.com/topic/59011-help-with-preg_replace-and-html-comments/
Share on other sites

<?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.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.