tags:

views:

117

answers:

3

Is there any function that makes string from PHP simpleXMLElement?

+1  A: 

Perhaps This is what you are looking for.

Gunner
No, I wanted to have something exactly opposite. From object to string.
liysd
I think this is what it does. YOu call the given objects asXML() method and you will get the string representation.
Gunner
A: 
$string = "<element><child>Hello World</child></element>";
$xml = new SimpleXMLElement($string);

$xml->asXML(); //The entire XML tree as a string
$xml->child->asXML(); //Just the child node as a string
Tim Cooper
+1  A: 

You can use the asXML method as:

<?php

// string to SimpleXMLElement
$xml = new SimpleXMLElement($string);

// make any changes.
....

// convert the SimpleXMLElement back to string.
$newString = $xml->asXML();
?>
codaddict