gpt4 book ai didi

php从url解析xml

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

http://www.bank.lv/vk/xml.xml?date=20130530

  $url = 'http://www.bank.lv/vk/xml.xml?date=20130530';
$xml = simplexml_load_file($url) or die("feed not loading");
$Rate = $xml->Currency[1]->Rate;
echo $Rate;
echo 'BREAK HTML';
echo "-----";
echo "// "; var_dump($xml); echo " //";

为什么HTML数据不输出?已经测试了很多教程,但不明白如何从此 XML 输出数据

最佳答案

你必须把

 $Rate = $xml->Currencies->Currency['1']->Rate;

代替

 $Rate = $xml->Currency[1]->Rate;

因为$xml结构是

   SimpleXMLElement Object
(
[Date] => 20130530
[Currencies] => SimpleXMLElement Object
(
[Currency] => Array
(
[0] => SimpleXMLElement Object
(
[ID] => AED
[Units] => 1
[Rate] => 0.14900000
)

[1] => SimpleXMLElement Object
(
[ID] => AUD
[Units] => 1
[Rate] => 0.52300000
)

[2] => SimpleXMLElement Object
(
[ID] => BGN
[Units] => 1
[Rate] => 0.35900000
)

[3] => SimpleXMLElement Object
(
[ID] => BYR
[Units] => 1000
[Rate] => 0.06290000
)



.
.
.

)

)

)

关于php从url解析xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16829375/

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