Jump to content

[SOLVED] delete everything between...


poe

Recommended Posts

 

i am reading an html file

 

i want to replace everything between these 2 tags but cant figure it out

 

<!-- REAP --> .... <!-- /REAP -->

<!-- REAP -->
         <!-- PURGE:/baseball/mlb/gameflash/2008/04/02/19662_recap.html -->
         <!-- KEEP --> | <a href="/baseball/mlb/gameflash/2008/04/02/19662_recap.html">Recap</a>
         <!-- /PURGE:/baseball/mlb/gameflash/2008/04/02/19662_recap.html -->

         <!-- /REAP -->

 

i have tried

$myHtml = eregi_replace("<\!--REAP-->(.*?)<\!--\/REAP-->", "", $myHtml);

 

but it doesnt work.

 

Warning: eregi_replace(): REG_BADRPT

 

Link to comment
Share on other sites

REG_BADRPT is given sometimes when special chars are not escaped. You can simply use preg_replace instead, it's faster most of the times too.

Also, you need wrap your "REAP"s with spaces (like in your html):

 

<?php

$myHtml = <<<DATA
<!-- REAP -->
         <!-- PURGE:/baseball/mlb/gameflash/2008/04/02/19662_recap.html -->
         <!-- KEEP --> | <a href="/baseball/mlb/gameflash/2008/04/02/19662_recap.html">Recap</a>
         <!-- /PURGE:/baseball/mlb/gameflash/2008/04/02/19662_recap.html -->

         <!-- /REAP -->
DATA;

$myHtml = preg_replace("#<\!-- REAP -->(.*?)<\!-- \/REAP -->#is", "", $myHtml);

?>

 

 

Orio.

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.