【问题标题】:How to move XML file data to PHP array?如何将 XML 文件数据移动到 PHP 数组?
【发布时间】:2018-02-21 07:02:32
【问题描述】:

这是我的 xml 数据

<?xml version="1.0" encoding="iso-8859-1"?>
<smslist>
 <sms>
  <cid>FIRSTCID</cid>
  <mid>FIRSTMID</mid>
  <mb>98389923</mb>
 </sms>
 <sms>
  <cid>SECONDCID</cid>
  <mid>SECONDMID</mid>
  <mb>76445645</mb>
 </sms>
...
</smslist>

如何将 cidmid 数据推送到 php 数组,例如 $array = array(("FIRSTCID","FIRSTMID"),("SECONDCID","SECONDMID")...)

如果这是一个重复的问题,请原谅。 :)

【问题讨论】:

    标签: php arrays xml


    【解决方案1】:

    你可以试试这个:

    $xml = new SimpleXMLElement($your_xml_string);
    $xml_array=[];
    foreach ($xml->smslist->sms as $sms) {
        $xml_array[]=array($sms->cid,$sms->mid);
    }
    

    【讨论】:

      【解决方案2】:

      通过使用 xml_parse_into_struct(),您可以将 XML 转换为数组,详细文档请查看以下链接。

      http://php.net/manual/en/function.xml-parse-into-struct.php

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-10-15
        • 1970-01-01
        • 1970-01-01
        • 2021-07-06
        • 1970-01-01
        • 2021-07-25
        • 1970-01-01
        相关资源
        最近更新 更多