我想从网址获取xml提要
http://api.eve-central.com/api/marketstat?typeid=1230®ionlimit=10000002
但似乎失败了.我试过了
> new SimpleXMLElement
,
> file_get_contents
和
> http_get
然而,当我回显或print_r时,这些似乎都没有回应一个很好的XML提要.最终目标是最终解析这些数据,但将其变为变量肯定是一个不错的开始.
我在下面附上了我的代码.这包含在一个循环中,$typeID确实提供了正确的ID,如上所示
$url = 'http://api.eve-central.com/api/marketstat?typeid='.$typeID.'®ionlimit=10000002'; echo $url."<br />"; $xml = new SimpleXMLElement($url); print_r($xml);
我应该说,我看到的另一个奇怪的事情是,当我回复$url时,我得到了
http://api.eve-central.com/api/marketstat?typeid=1230®ionlimit=10000002
请尝试以下方法:
原文链接:https://www.f2er.com/php/137966.html<?PHP $typeID = 1230; // set Feed URL $url = 'http://api.eve-central.com/api/marketstat?typeid='.$typeID.'®ionlimit=10000002'; echo $url."<br />"; // read Feed into SimpleXML object $sxml = simplexml_load_file($url); // then you can do var_dump($sxml); // And now you'll be able to call `$sxml->marketstat->type->buy->volume` as well as other properties. echo $sxml->marketstat->type->buy->volume; // And if you want to fetch multiple IDs: foreach($sxml->marketstat->type as $type){ echo $type->buy->volume . "<br>"; } ?>