$text = "<p>keep me</p> <p>strip me </p>
$pattern = "/<[^\/>]*>(\ \;)*<\/[^>]*>/";
$text = preg_replace($pattern, '', $text);
Hi, I need to strip “quasi-empty” p tags from a html string. there’s always only a as a trigger in the p element. how can I strip it with regex?
The following pattern will match all
<p> </p>blocks that include along with any accompanying text, as per your example.If you actually want it to only strip out
<p> </p>blocks with and spaces, use the following pattern instead:If you want to only strip out
<p> </p>blocks that have an and up to a certain number of characters, use the following (setting the$maxCharsvariables as you see fit):