Is there any function that makes string from PHP SimpleXMLElement
?
The simplexml_load_string() function converts a well-formed XML string into an object.
The PHP simplexml_load_string() function is used to read XML data from a string.
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>" $xml->asXML(); // Just the child node as a string: // "<child>Hello World</child>" $xml->child->asXML();
You can use casting:
<?php $string = "<element><child>Hello World</child></element>"; $xml = new SimpleXMLElement($string); $text = (string)$xml->child;
$text will be 'Hello World'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With