我想用php解析這個page。我寫了這個代碼,但它給了我一個錯誤 - ()的foreach爲無效的論點提供用php解析xml文件時出錯
$opts = array('http' => array('header' => 'Accept-Charset: UTF-8, *;q=0'));
$context = stream_context_create($opts);
$data = file_get_contents('http://cbr.ru/scripts/XML_daily.asp',false, $context);
$xml = simplexml_load_string($data);
foreach($xml->valcurs->valute as $val){
echo "<p>".$val->attributes()->numcode."</p>";
}
'var_dump($ xml-> valcurs-> valute)' - 發佈結果 – Oxymoron
@Oxymoron'null' – Rulisp
@Rulisp您已檢查過您$ xml'包含數據,對不對? – NewInTheBusiness