How to remove empty paragraph tags from string?

use this regex to remove empty paragraph

/<p[^>]*><\\/p[^>]*>/

example

<?php
$html = "abc<p></p><p>dd</p><b>non-empty</b>"; 
$pattern = "/<p[^>]*><\\/p[^>]*>/"; 
//$pattern = "/<[^\/>]*>([\s]?)*<\/[^>]*>/";  use this pattern to remove any empty tag

echo preg_replace($pattern, '', $html); 
// output
//abc<p>dd</p><b>non-empty</b>
?>

Leave a Comment

tech