Remove <p><br/></p> with DOMxpath or regex?
问题 I use DOMxpath to remove html tags that have empty text node but to keep <br/> tags, $xpath = new DOMXPath($dom); while(($nodeList = $xpath->query('//*[not(text()) and not(node()) and not(self::br)]')) && $nodeList->length > 0) { foreach ($nodeList as $node) { $node->parentNode->removeChild($node); } } it works perfectly until I came across another problem, $content = '<p><br/><br/><br/><br/></p>'; How do remove this kind of messy <br/> and <p> ? which means I don't want to allow <br/> alone