私は(ECB)、欧州中央銀行のcurrentcy為替レートフィードを使用しようとしています http://www.ecb.int/stats/eurofxref/eurofxref-daily.xmlPHPの解析為替レートのフィードXML
私:allow_url_fopen = Onが設定されていることを確認しました。例えば
http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html
、私が使用されるが、それは何をエコーしないと、$ XMLオブジェクトは常に空であるようです。
<?php
//This is aPHP(5)script example on how eurofxref-daily.xml can be parsed
//Read eurofxref-daily.xml file in memory
//For the next command you will need the config option allow_url_fopen=On (default)
$XML=simplexml_load_file("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
//the file is updated daily between 2.15 p.m. and 3.00 p.m. CET
foreach($XML->Cube->Cube->Cube as $rate){
//Output the value of 1EUR for a currency code
echo '1€='.$rate["rate"].' '.$rate["currency"].'<br/>';
//--------------------------------------------------
//Here you can add your code for inserting
//$rate["rate"] and $rate["currency"] into your database
//--------------------------------------------------
}
?>
更新:
私は私のテスト環境でプロキシの背後午前として、私はこれを試してみましたが、それでも私は、XMLを読むために得ることはありません: 関数カール($のURL){ $ CH = curl_init(); curl_setopt($ ch、CURLOPT_URL、$ url);
curl_setopt($ ch、CURLOPT_RETURNTRANSFER、1);
curl_close($ ch);
return curl_exec($ ch); }
$address = urlencode($address);
$data = curl("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml");
$XML = simplexml_load_file($data);
var_dump($XML); -> returns boolean false
私を助けてください。ありがとう!
var_dump($ XML)とは何ですか? – noli
あなたはエラー報告をしていますか、それは何を言いますか? PHP5を使用していて、 'php.ini'でXMLサポートが有効になっていますか?スクリプトは私のローカルコンピュータから機能しますので、あなたの側や銀行の終わりに一時的なネットワークの問題がありますか? –
私のシステムで動作します。あなたは 'allow_url_fopen = On'を持っているので、' allow_url_include = On'を追加してみてください。 –