Menu principale:
<?xml version="1.0" encoding="UTF-8"?> <user> <firstName>Simone</firstName> <lastName>DAmico</lastName> <birthDate>2000-01-01</birthDate> <country>IT</country> </user>
$xml = <<<XML <?xml version="1.0" encoding="UTF-8"?> <user> <firstName>Simone</firstName> <lastName>DAmico</lastName> <birthDate>2000-01-01</birthDate> <country>IT</country> </user> XML; $user = new SimpleXMLElement($xml); var_dump($user);
object(SimpleXMLElement)#1 (4) { ["firstName"]=> string(6) "Simone" ["lastName"]=> string(6) "DAmico" ["birthDate"]=> string(6) "2000-01-01" ["country"]=> string(6) "IT" }
$user = (array)new SimpleXMLElement($xml); var_dump($user);
echo $user['firstName'];
$user = [ 'firstName' => 'Simone', 'lastName' => 'D\'Amico', 'age' => 30 ]; $xml = new SimpleXMLElement(''); foreach ($user as $key => $value) { $xml->addChild($key, $value); } echo $xml->asXML();
<?xml version="1.0"?> <user><firstName>Simone</firstName><lastName>D'Amico</lastName><age>30</age></user>