我正在调用某个网址:http://example.com/Service.asmx/getTodaysDiscussionForum
这是xml数据,请参见屏幕截图:
$response = file_get_contents('http://103.1.115.87:100/Service.asmx/getTodaysDiscussionForum');
$response = new SimpleXMLElement($response);
print_r($response);exit;
显示以下输出:
SimpleXMLElement Object (
[Table1] => Array ( [0] => SimpleXMLElement Object (
[Id] => 1210 [Title] => Test Discussion, Dont Reply [CreatedDate] => 4/25/2014 10:42:49 AM
[Status] => Not Sent )
[1] => SimpleXMLElement Object (
[Id] => 1182 [Title] => Negotiation Skills discussion [CreatedDate] => 4/25/2014 7:47:51 AM
[Status] => Not Sent )
)
)
如何将每个数据存储在变量中?
我提前感谢这位xml阅读的新手
答案 0 :(得分:1)
$xml = simplexml_load_string($xmlstring);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
答案 1 :(得分:0)
<?php
foreach($response[0] as $data) {
$id = $data->Id;
//...
}