Jump to content

[SOLVED] Yet another Regex request...


Atomic Taco

Recommended Posts

How specific is your search and replace?  Is it just replacing the text between tags with empty string?  Please explain.

Yes, just replace the text between > and < with empty string.  But the input is going to have many nested tags, and there will already be an empty string between some > and <.

$str = '<br><a href="test.gif">link</a><br><p>Some more text here</p>';
$arr = preg_split('#(<[^>]+>)#', $str, -1, PREG_SPLIT_DELIM_CAPTURE);
foreach($arr as $val){
   if(!empty($val) && strpbrk($val, '<')){
      $newStr .= $val;
   }
}
echo $newStr;

 

Ouput:

<br><a href="test.gif"></a><br><p></p>

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.