How to remove unwanted
tags using pregmatch in below cases. i wrote pregmatch but its not working for some cases. here is my string
<?php
$str='<div class="borderdummydiv" style="padding: 10px;">
<div class="showcolsec" style="line-height: normal;">
<p style="font-size: 14px;" data-mce-style="font-size: 14px;"><strong>Email Template for Testing - 01:</strong></p><p style="font-size: 14px;" data-mce-style="font-size: 14px;"><br data-mce-bogus="1"></p><p style="font-size: 14px;" data-mce-style="font-size: 14px;">Email body for testing the autoresponder mails and email blasts scheduling functionality<br data-mce-bogus="1"></p>
<p></p>
<p><br></p>
<p></br></p>
<p> </br></p>
<p> <br class="ddd"></p>
<p class="ddd"></p>
<p class="ddd"><br class="ddd"></p>
<p class="ddd"></br></p>
<p class="ddd"> </br></p>
<p class="ddd"> <br class="ddd"></p>
</div>
</div>';
//echo $str;
echo preg_replace("/<p[^>]*>[\s| |<\br [^>]*>|<\/br>]*<\/p>/", '', $str);
?>
Below are unwanted paragraphs. so how can i remove from string
<p></p>
<p><br></p>
<p></br></p>
<p> </br></p>
<p> <br class="ddd"></p>
<p class="ddd"></p>
<p class="ddd"><br class="ddd"></p>
<p class="ddd"></br></p>
<p class="ddd"> </br></p>
<p class="ddd"> <br class="ddd"></p>
In your regexp in the part <\br [^>]*> you escape the "b" with a backslash. By that you make it a backspace. I think you don't want that.
Try to remove that backslash which then makes it:
echo preg_replace("/<p[^>]*>[\s| |<br [^>]*>|<\/br>]*<\/p>/", '', $str);
EDIT: (because of new information by the questioner) OK, with this one it works:
echo preg_replace("/<p[^>]*>(\s| |<br [^>]*>|<\/?br>)*<\/p>/", '', $str);
Had to replace the square brackets by round ones and make the slash before "br" optional.