simplexml_load_file 直接使用此函數:
header("Content-type:text/html;Charset=utf-8");
$content = simplexml_load_file('http://rss.sina.com.cn/news/allnews/sports.xml');
//print_r($content);
foreach ($content->channel->item as $key => $value) {
echo $value->title.'<br/>'.$value->link.'<br/>';
}
如果是這種類型
<rss version="2.0">
<channel>
<title>
<![CDATA[焦點新聞-新浪體育]]>
</title>
.....
那麼title就是一個對象裏面的值 即
foreach ($content->channel as $key => $value) {
echo $value->title.'<br/>';
}
<xml_api_reply version="1">
<weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
......
modeul_id, tab_id等就是數組裏的值
foreach ($content['weather'] as $key => $value) {
echo $value['module_id'].'<br/>';
}