The following pattern will match all <p> </p>
blocks that include
along with any accompanying text, as per your example.
$text = "<p>keep me</p> <p>strip me </p>";
$pattern = "/<p>[^<]* \;[^<]*<\/p>/";
$output = preg_replace($pattern, '', $text);
If you actually want it to only strip out <p> </p>
blocks with
and spaces, use the following pattern instead:
$pattern = "/<p>(\s* \;\s*)+<\/p>/";
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 $maxChars
variables as you see fit):
$maxCharsBefore = 10;
$maxCharsAfter = 10;
$pattern = "/<p>[^<]{0,".$maxCharsBefore."} \;[^<]{0,".$maxCharsAfter."}<\/p>/";