如何打一个网址,并使用PHP下载其XML [英] How to hit a url and download its xml using php
本文介绍了如何打一个网址,并使用PHP下载其XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试过从网址获取xml,甚至smottt的想法从 PHP如何打开一个网址并下载它的XML ,但没有为我工作。
I tried everything to get the xml from the url, even smottt idea from PHP How to hit a url and download its xml , but didnt work for me.
我的场景;
产生美元汇率的网址:
nrb.org.np/exportForexXML.php?YY=2015&MM=03&DD = 01& YY1 = 2015& MM1 = 03& DD1 = 01
这里: YY MM DD YY1 MM1 DD1 是报告的结束日期。我相信,它在亚洲加德满都的unix时间生成一个xml。每次和第二个单独的xml文件名。
Here: YY MM DD are the starting date and YY1 MM1 DD1 are the ending date of report. I believe , it generates an xml in unix time of Kathmandu, Asia. Everytime and second seperate xml file name.
搜索互联网但没有任何内容,
Searched internet but nothing,
请帮助。
感谢提前
编辑:我使用的代码是
$url = "nrb.org.np/exportForexXML.php?YY=2015&MM=03&DD=01&YY1=2015&MM1=03&DD1=01";
$xml = new SimpleXMLElement($url, null, true);
foreach($xml->CurrencyConversionResponse as $CurrencyConversionResponse) {
echo $CurrencyConversionResponse->BaseCurrency . "<br />";
echo $CurrencyConversionResponse->TargetCurrency . "<br />";
echo $CurrencyConversionResponse->ConversionTime . "<br />";
echo $CurrencyConversionResponse->ConversionRate . "<br />";
}
错误讯息是
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: I/O warning : failed to load external entity "nrb.org.np/exportForexXML.php?YY=2015&MM=03&DD=01&YY1=2015&MM1=03&DD1=01" in C:\xampp\htdocs\xml.php on line 4
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\xampp\htdocs\xml.php:4 Stack trace: #0 C:\xampp\htdocs\xml.php(4): SimpleXMLElement->__construct('nrb.org.np/expo...', 0, true) #1 {main} thrown in C:\xampp\htdocs\xml.php on line 4
推荐答案
$ c> http:// 到网址
Add the http://
to the URL
$url = "http://nrb.org.np/exportForexXML.php?YY=2015&MM=03&DD=01&YY1=2015&MM1=03&DD1=01";
$xml = new SimpleXMLElement($url, null, true);
foreach($xml->CurrencyConversionResponse as $CurrencyConversionResponse) {
echo $CurrencyConversionResponse->BaseCurrency . "<br />";
echo $CurrencyConversionResponse->TargetCurrency . "<br />";
echo $CurrencyConversionResponse->ConversionTime . "<br />";
echo $CurrencyConversionResponse->ConversionRate . "<br />";
}
这篇关于如何打一个网址,并使用PHP下载其XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文