- simplexml_import_dom: documentation ( source)
<?php
$raw_html = <<<EOF
<p>
Some text here <strong class="wanna-attributes-too">with strong element!</strong>.
But there can be even <b>bold</b> tag and many others.
</p>
EOF;
$dom = new DOMDocument();
$dom->loadHTML($raw_html);
$html = simplexml_import_dom($dom);
echo $html->asXML();