我注意到PEAR XML_Serializer
和XML_Unserializer
不是“可逆的”,例如:
<?php
$a = array(1, 2);
$serializer = new XML_Serializer();
$serializer->serialize($a);
$b = $serializer->getSerializedData();
print($b); // "<array><XML_Serializer_Tag>1</Xml_Serializer_Tag><XML_Serializer_Tag>2</Xml_Serializer_Tag></array>"
$unserializer = new XML_Unserializer();
$unserializer->unserialize($b);
$c = $unserializer->getUnserializedData();
print_r($c); // array('XML_Serializer_Tag' => array(1, 2)) instead of array(1, 2)
XML_Unserializer
是否有任何选项可以递归删除Xml_Serializer_Tag
?
答案 0 :(得分:0)
我在XML_Unserializer options PEAR Documentation
中找到了答案我在上面的代码中修改了一行并且它有效:
$unserializer = new XML_Unserializer(array(XML_UNSERIALIZER_OPTION_IGNORE_KEYS => array('XML_Serializer_Tag')));
太糟糕了,这不是默认值......