SimpleXml 到 string
有没有函数可以从PHP制作字符串?SimpleXMLElement
您可以使用 SimpleXMLElement::asXML()
方法来完成此操作:
$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();
您可以使用转换:
<?php
$string = "<element><child>Hello World</child></element>";
$xml = new SimpleXMLElement($string);
$text = (string)$xml->child;
$text将是“Hello World”