xml2array 抓取RSS資料

一直很想試著去抓RSS再轉成自己的網頁內容,今天就去找到這個方法,可以看這個部落格的介紹。

使用方法是先去下載這個php
http://www.doremicat.com/upload/files//xml2array.7z

然後用php去呼叫
<?
require('xml2array.php'); //在寫程式的時候先載入xml2array.php
$rss_file = 'http://rss.chinatimes.com/rss/latestnews-u.rss'; //填入我們剛所複制的網址
$content = file_get_contents($rss_file); //取得資料
$result = xml2array($content); //丟給xml2array處理
//for ($i=0;$i<count($result['rss']['channel']['item']);$i++) { //列出所有筆數
?>

要連結用這個
iconv("UTF-8","big5",$result['rss']['channel']['item'][$i]['link'])
要標題用這個
iconv("UTF-8","big5",$result['rss']['channel']['item'][$i]['title'])
大概是這樣,我有測試成功,還蠻方便的,可以試試看。

留言