接口说明:
XML解析,转换为数组,或JSON格式
接口源代码PHP:
<?php
/**
* XML转JSON数组 PHP接口源代码
*
* 最后修改:2024-10-12 16:11:02
*
* @author dogstar www.yesapi.cn
*
* 来源:https://open.yesapi.cn/apicode/8859.html
*/
function ($params, $di) {
$xml = "<note>
<to>收件人</to>
<from>发送人</from>
<heading>头部</heading>
<body>正文内容:Don't forget me this weekend!</body>
</note>";
if($xml == '') return '';
//禁止引用外部xml实体
libxml_disable_entity_loader(true);
$xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
return json_decode(json_encode($xmlstring), true);
}
在线运行
