生有涯学无涯

蝼蚁虽小可溃千里江堤

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

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/antdz/article/details/49907407
文章标签: php rss instagram
个人分类: php
上一篇Windows(多)操作系统启动过程
下一篇thinkphp整合ueditor上传功能
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭