What are the best practices for handling XML declarations in PHP when parsing XML strings?

When parsing XML strings in PHP, it's important to handle XML declarations properly to avoid parsing errors. One common issue is when the XML declaration (<?xml version="1.0" encoding="UTF-8"?>) is present in the XML string. To handle this, you can use the `LIBXML_NOXMLDECL` option in the `simplexml_load_string` function to ignore the XML declaration.

$xmlString = &#039;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;root&gt;&lt;example&gt;Example content&lt;/example&gt;&lt;/root&gt;&#039;;

// Load the XML string with the LIBXML_NOXMLDECL option to ignore the XML declaration
$xml = simplexml_load_string($xmlString, null, LIBXML_NOXMLDECL);

// Access elements in the XML
echo $xml-&gt;example;