PHP XML序列化从对象/数组缩进(替换pear/XML_serializer)


PHP XML Serialisation from object/array with indentation (replacement of pear/XML_serializer)

pear/XML_Serializer可以接受indent参数,该参数将用作缩进字符(以获得人类可读的,格式良好的XML)

我想找一个替代这个包,但是没有类似的功能。

谁能给个解决办法?

Symfony/Serializer可以使用xml_format_output

use 'Symfony'Component'Serializer'Serializer;
use 'Symfony'Component'Serializer'Encoder'XmlEncoder;
$serializer = new Serializer(array(), new XmlEncoder());
$array = array('your' => 'data');
echo $serializer->serialize($array, 'xml', array('xml_format_output' => true));