- preg_replace: documentation ( source)
<?php
$strings[] = '<p> Test string<br> </p> <p> <br> </p> <p> <br> </p>';
foreach($strings as $string){
// \s* matches any number of whitespace characters (" ", \t, \n, etc)
// (?:...)+ matches one or more (without capturing the group)
// $ forces match to only be made at the end of the string
$string = preg_replace("/(?:<p>\s*(?:<br>\s*)+<\/p>\s*)+$/", "", $string);
echo $string."\n---\n";
}