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
https://forums.phpfreaks.com/topic/100358-solved-delete-everything-between/
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.

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.