国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

PHP如何將XML轉成數組

2024-05-04 23:44:42
字體:
來源:轉載
供稿:網友
這篇文章主要為大家詳細介紹了PHP將XML轉成數組的方法,感興趣的朋友可以參考一下
 

如果你使用 curl 獲取的 xml data
xml=simplexmlloadstring(data);
data[′tk′]=jsondecode(jsonencode(xml),TRUE);

如果是直接獲取 URL 數據的話
xml=simplexmlloadfile(data);
data[′tk′]=jsondecode(jsonencode(xml),TRUE);

先把 simplexml 對象轉換成 json,再將 json 轉換成數組。

代碼:

<?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)

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



注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 溧阳市| 舞阳县| 佛冈县| 廊坊市| 井冈山市| 南川市| 登封市| 读书| 石渠县| 芜湖市| 乐东| 高雄市| 定襄县| 屏边| 利津县| 扎兰屯市| 庆安县| 桐乡市| 邯郸县| 元阳县| 郯城县| 杨浦区| 云龙县| 图片| 盘锦市| 吉水县| 南汇区| 五寨县| 临海市| 津市市| 武胜县| 甘洛县| 渑池县| 巨鹿县| 马龙县| 波密县| 五大连池市| 怀来县| 谷城县| 于田县| 大庆市|