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

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

 更新時間:2016年04月04日 19:13:19   作者:飛鴻影~  
這篇文章主要為大家詳細介紹了PHP將XML轉成數(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 對象轉換成 json,再將 json 轉換成數(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)容,希望對大家的學習有所幫助。

相關文章

最新評論

吐鲁番市| 余姚市| 灯塔市| 长治市| 松原市| 从化市| 思茅市| 灵宝市| 教育| 尉氏县| 南昌市| 彰化县| 久治县| 渝北区| 靖宇县| 遂平县| 澎湖县| 太仓市| 嘉祥县| 新津县| 南木林县| 二连浩特市| 西青区| 龙口市| 政和县| 成武县| 铜鼓县| 伊川县| 淮滨县| 灵丘县| 北京市| 宁陕县| 崇阳县| 昌图县| 昭苏县| 托里县| 大悟县| 华池县| 临颍县| 白水县| 金寨县|