gpt4 book ai didi

php - 从 URL 获取 xml 到变量

转载 作者:可可西里 更新时间:2023-11-01 12:30:56 26 4
gpt4 key购买 nike

我正在尝试从 url 获取 xml 提要

http://api.eve-central.com/api/marketstat?typeid=1230&regionlimit=10000002

但似乎失败得很惨。我试过了

然而,当我 echoprint_r 时,这些似乎都无法回显漂亮的 XML 提要。最终目标是最终解析这些数据,但将其放入变量中肯定是一个不错的开始。

我在下面附上了我的代码。这包含在一个循环中,$typeID 实际上给出了正确的 ID,如上所示

$url = 'http://api.eve-central.com/api/marketstat?typeid='.$typeID.'&regionlimit=10000002';
echo $url."<br />";
$xml = new SimpleXMLElement($url);
print_r($xml);

我应该说我看到的另一件奇怪的事情是当我回显 $url 时,我得到了

http://api.eve-central.com/api/marketstat?typeid=1230®ionlimit=10000002

®为注册商标符号。我不确定这是我浏览器中的“功能”,还是我代码中的“功能”

最佳答案

尝试以下操作:

<?php
$typeID = 1230;
// set feed URL
$url = 'http://api.eve-central.com/api/marketstat?typeid='.$typeID.'&regionlimit=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>";
}
?>

关于php - 从 URL 获取 xml 到变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14105922/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com