请知悉:本文最近一次更新为 1 year 前,文中内容可能已经过时。

有xml文件,PHP如何如何将xml转换为数组呢?

随手搜了下,主要利用了json的编码和反编码实现,示例代码如下:

$xml = '<?xml version="1.0" encoding="utf-8"?>

<res>

<test>test</test>

<test1>test1</test1>

<test2>test2</test2>

</res>';

$xml =simplexml_load_string($xml); //xml转object

$xml= json_encode($xml); //objecct转json

$xml=json_decode($xml,true); //json转array

echo '<pre>';

print_r($xml);

参考资料

php怎么将xml转换成数组


如您从本文得到了有价值的信息或帮助,请考虑扫描文末二维码捐赠和鼓励。

尊重他人劳动成果。转载请务必附上原文链接,我将感激不尽。


与《PHP如何将xml转换为数组》相关的博文:


留言

avatar
😀
😀😁😂😅😭🤭😋😘🤔😰😱🤪💪👍👎🤝🌹👌