最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP如何將XML轉(zhuǎn)成數(shù)組

 更新時間:2016年04月04日 19:13:19   作者:飛鴻影~  
這篇文章主要為大家詳細介紹了PHP將XML轉(zhuǎn)成數(shù)組的方法,感興趣的朋友可以參考一下

如果你使用 curl 獲取的 xml data
xml=simplexmlloadstring(data);
data[′tk′]=jsondecode(jsonencode(xml),TRUE);
如果是直接獲取 URL 數(shù)據(jù)的話
xml=simplexmlloadfile(data);
data[′tk′]=jsondecode(jsonencode(xml),TRUE);

先把 simplexml 對象轉(zhuǎn)換成 json,再將 json 轉(zhuǎn)換成數(shù)組。

代碼:

<?php
$string = <<<XML
<?xml version='1.0'?> 
<document>
 <title>Forty What?</title>
 <from>Joe</from>
 <to>Jane</to>
 <body>
 I know that's the answer -- but what's the question?
 </body>
</document>
XML;

$xml=simplexml_load_string($string);
$data = json_decode(json_encode($xml),TRUE);
var_dump( $xml );
var_dump( $data );
object(SimpleXMLElement)[1]
 public 'title' => string 'Forty What?' (length=11)
 public 'from' => string 'Joe' (length=3)
 public 'to' => string 'Jane' (length=4)
 public 'body' => string '
 I know that's the answer -- but what's the question?
 ' (length=57)
array
 'title' => string 'Forty What?' (length=11)
 'from' => string 'Joe' (length=3)
 'to' => string 'Jane' (length=4)
 'body' => string '
 I know that's the answer -- but what's the question?
 ' (length=57)

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助。

相關(guān)文章

最新評論

临潭县| 禹城市| 尼勒克县| 遵义县| 纳雍县| 酒泉市| 东兰县| 酒泉市| 博罗县| 克什克腾旗| 台南市| 新郑市| 哈密市| 大庆市| 东方市| 错那县| 合水县| 灯塔市| 汪清县| 松滋市| 远安县| 绥德县| 苏尼特右旗| 屯昌县| 徐州市| 金湖县| 张家口市| 荥经县| 安新县| 遵化市| 疏附县| 彩票| 武宁县| 马龙县| 清流县| 都昌县| 大化| 日喀则市| 广汉市| 靖江市| 萨迦县|