Fonction simplexml_load_string() de PHP

Définition et utilisation

La fonction simplexml_load_string() charge une chaîne XML dans un objet.

Si l'échec, retourne false.

语法

simplexml_load_file(string,class,options,ns,is_prefix)
Paramètres Description
string Obligatoire. Définit la chaîne XML à utiliser.
class Optionnel. Définit la classe du nouveau objet.
options Optionnel. Définit les paramètres supplémentaires de Libxml.
ns Optionnel.
is_prefix Optionnel.

Retourne la valeur

Retourne un objet de la classe SimpleXMLElement, whose properties contain the data of the XML document. If it fails, it returns false.

Exemple

<?php
$xmlstring = <<<XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George</to>
<from>John</from>
<heading>Rappel</heading>
<body>Ne pas oublier la réunion!</body>
</note>
XML;
$xml = simplexml_load_string($xmlstring);
var_dump($xml);
?>

Sortie :

object(SimpleXMLElement)#1 (4)
{
["to"]=> string(4) "George"
["from"]=> string(4) "John"
["heading"]=> string(8) "Rappel"
["body"]=> string(29) "Ne pas oublier la réunion!"
}