What are the recommended methods for storing XML data in variables in PHP?
When storing XML data in variables in PHP, it is recommended to use SimpleXMLElement or DOMDocument to parse and manipulate the XML. These classes provide methods to load XML data from a string or file, allowing for easy access to the XML structure and data.
// Store XML data in a variable using SimpleXMLElement
$xmlString = '<data><name>John</name><age>30</age></data>';
$xml = new SimpleXMLElement($xmlString);
// Access and print XML data
echo $xml->name; // Output: John
echo $xml->age; // Output: 30