liysd liysd - 9 months ago 52
PHP Question

SimpleXml to string

Is there any function that makes string from PHP simpleXMLElement?


You can use the SimpleXMLElement::asXML() method to accomplish this:

$string = "<element><child>Hello World</child></element>";
$xml = new SimpleXMLElement($string);

// The entire XML tree as a string:
// "<element><child>Hello World</child></element>"

// Just the child node as a string:
// "<child>Hello World</child>"