Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.