I have two questions:
I am using TinyMCE editor and I want to remove empty tags from HTML. I am getting error "DOMDocument::loadHTML(): Unexpected end tag : p" when I pass text from TinyMCE editor and this error disappears when I directly pass text to TinyMCE strange! Please see code below.
How do I prevent warning from DomDocument when incorrect HTML is passed?.
<strong>Bold Item </b></strong>
?
Here is an example text
<p style="text-align: justify;"> </p>
<p>blah blah blah <strong></strong>.</p>
<p style="text-align: justify;"> </p>
<p>paragraph three!!.</p>
My function
function remove_empty_tags ($text) {
$dom = new DOMDocument;
$dom->loadHTML($text);
// fetch all the wanted nodes
$xp = new DOMXPath($dom);
foreach($xp->query('//*[not(node() or self::br) or normalize-space() = ""]') as $node) {
$node->parentNode->removeChild($node);
}
// output the cleaned markup
return $dom->saveXml($dom->getElementsByTagName('body')->item(0) );
}
echo remove_empty_tags($_POST['mce_editor']);