How can additional output, such as fragmented tags, be avoided when working with DOMDocument in PHP?

When working with DOMDocument in PHP, additional output like fragmented tags can be avoided by setting the formatOutput property of the DOMDocument object to true. This will ensure that the output is formatted properly with indentation and line breaks.

$dom = new DOMDocument();
$dom->formatOutput = true;

// Your DOMDocument manipulation code here

echo $dom->saveXML();