How can DOMDocument be used to create XML strings in PHP?
To create XML strings in PHP using DOMDocument, you can create a new DOMDocument object, then create elements and attributes using the DOMDocument methods, and finally output the XML string using the saveXML() method.
// Create a new DOMDocument object
$doc = new DOMDocument();
// Create root element
$root = $doc->createElement('root');
$doc->appendChild($root);
// Create child element with attribute
$child = $doc->createElement('child');
$child->setAttribute('attribute', 'value');
$root->appendChild($child);
// Output XML string
$xmlString = $doc->saveXML();
echo $xmlString;