[PHP] 使用 php 抓取 blogger 的 RSS

標籤: PHP RSS Blogger

記錄一下用 PHP 抓取 blogger RSS 的方法:

//blogger 的 rss feed 連結,即使是已經自訂網址也能使用
$file = "http://[YOUR_BLOGSPOT_ACCOUNT].blogspot.com/atom.xml";
//讀取 RSS
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");
//讀取部落格文章
$xml =  $xml ->entry;
//跑迴圈
foreach( $xml as $row )
{
/ Load the entry publish time 
 $dtime = date("D jS M, Y", strtotime(strtok($row->published, 'T')));
 // Load the link of each blog entry
 $titlelink = $row->link[4]["href"];
 // Load the text for Comment and comment counts
 $comments = $row->link[1]["href"];
 $comm = $row->link[1]["title"][0]; 

 /* Display the contents (use your own imaginations here =).) */
   $row->title;
 // Display blog entry content
   $row->content;
 // Display number of comments
   $comm;
}

 

參考:How to parse RSS Feed XML from Blogspot using PHP