天天看點

php建構RSS

php建構RSS
雖然說RSS已經過時了,但是還有人喜歡用他。昨天有人在貼吧求助寫一個RSS,我心一熱就答應其做一下。其中用到了RSSbuilder.class.php和Instagram.class.php。好久沒有寫代碼了,寫得有點爛,湊合着看吧。
<?php
/**
 * Instagram Rss Builder
 * name:rss.php
 * BY AntDz
 * 2015-11-18
 (c) Copyright 2015 Administrator. All Rights Reserved.
 * */
require ('rssbuilder.class.php');

header('Content-Type: application/xml; charset=utf-8');
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Fri, 14 Mar 1980 20:53:00 GMT');
header('Last-Modified: ' . date('r'));
header('Pragma: no-cache');

$rss = new RSSBuilder('utf-8', 'http://antdz.iteye.com', 'Instagram RSS', 'Instagram RSS BY AntDz');
$rss -> addDCdata('http://antdz.iteye.com', 'http://antdz.iteye.com', date('r'));
$ver = '2.00'; //rss版本

 /*file_get_contents()讀取json
$jsondata = file_get_contents("https://api.instagram.com/v1/users/self/feed?access_token=545490633.2e7067c.2d7378e20775421fadac61fc778965c8");
$arraydata = json_decode($jsondata, TRUE);
$usedata = $arraydata['data'];*/
//擷取數組中的data

/*curl讀取json*/
require_once ("Instagram.class.php");
$instagram = Instagram::getFeed2('545490633.2e7067c.2d7378e20775421fadac61fc778965c8');
$usedata=$instagram['data'];

foreach ($usedata as $val) {
    $name = "";
    if ($val['user']['full_name'] == "") {
        $name = $val['user']['username'];
    } else {
        $name = $val['user']['full_name'];
    }
    $rss -> addItem('', "<![CDATA[" . $val['caption']['text'] . "]]>", $val['link'], "<![CDATA[" . $val['caption']['text'] . "<br><img  src='" . $val['images']['low_resolution']['url'] . "'/>]]>", $val['type'], date('r', $val['created_time']), "<![CDATA[" . $name . "]]>");
}
$rss -> outputRSS($ver);
?>
           

項目位址:https://code.csdn.net/antdz/instagram_rss