我正在使用simplexml_load_file
加载BBC Weather RSS提要,它随机给出以下错误:
Warning: simplexml_load_file() [function.simplexml-load-file]: :1: parser error : Start tag expected, '<' not found in
它似乎是随机失败的。我的代码不是动态变化的,所以我不知道为什么它有时会失败。
如果我获取"推测"有缺失<
标记的rss文件,并将其存储在我的计算机上,并将simplexml_load_file
指向该位置,它就可以正常工作。
作为这个小问题,任何建议都会让我抓狂。
试试这个卷曲
<?php
$k = 'http://open.live.bbc.co.uk/weather/feeds/en/2656173/3dayforecast.rss';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $k);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$rss = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($rss, 'SimpleXMLElement', LIBXML_NOCDATA);
echo "<pre>";
print_r($xml);
echo "</pre>";
// if you want all items
//$xml->channel->item item is a array
//So
foreach($$xml->channel->item as $item){
echo $item->title; // you can get all results here
}
?>