Jump to content

[SOLVED] Remove text between two HTML comments.


JasonLewis

Recommended Posts

I'm not sure why this isn't working, but it isn't. I just can't seem to get it.

 

This is my expression:

$tmp_tpl = preg_replace("#<!--COMMENTBOX-->(.*?)<!--ENDCOMMENTBOX-->#", "", $tmp_tpl);

 

I just want to replace ANYTHING between the two tags with nothing.

 

Cheers everyone.

Link to comment
Share on other sites

Well, one way is to make use of assertions. By using look behind and look ahead assertions (they are not included in any matches), you can grab what is not part of them:

 

$tmp_tpl = preg_replace('#(?<=<!--COMMENTBOX-->).+(?=<!--ENDCOMMENTBOX-->)#', '', $tmp_tpl);

 

Of course, to test this out, when you say echo $tmp_tpl, you won't see anything, as these are comment tags (and thus do not display). So you would have to right-click and view source to see the '<!--COMMENTBOX--><!--ENDCOMMENTBOX-->' effect.

 

Cheers,

 

NRG

Link to comment
Share on other sites

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.