六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 56|回复: 0

php 做的RSS采集

[复制链接]

升级  80%

8

主题

8

主题

8

主题

童生

Rank: 1

积分
40
 楼主| 发表于 2013-1-25 03:27:46 | 显示全部楼层 |阅读模式
      之前一直想在自己的网站上加一些RSS新闻链接,显示新闻摘要,并连接到出处。
今天有时间自己整理了下,公司只能上ITEye,贴上代码,备查。
<html><head><title>CB采集测试</title></head><style>h3 {}h5 {}.content {border:1px #BAE4FD solid; background-color:#E8E8FF;width:600px;font-family:Microsoft Yahei; margin-top:10px;padding:2px;}#doe {float:left;width;96px;height:96px;img:url(logo.jpg);}</style><?phpfunction load_file($url) {             $ch = curl_init($url);             // Return http response in string             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);             $xml = simplexml_load_string(curl_exec($ch));             return $xml;    }function cbTimeSet($cbtime){date_default_timezone_set('Asia/Shanghai'); $pubDate = date('Y-m-d H:i:s', strtotime($cbtime));return $pubDate;}    $feedurl = 'http://localhost/rss/backend.xml';         $rss = load_file($feedurl); ?><body ><?php    foreach ($rss->channel->item as $item) {echo "<div class=\"content\" >";        echo "<h3>[".$item->category."]<a href=". $item->link ."?f=mail.fbse.cn>" . $item->title . "</a></h3>".$item->pubDate."---".cbTimeSet($item->pubDate);echo "<div id= doe></div>";        echo "<p>" . $item->description . "</p>"; echo "</div>";    }echo $rss;////date_default_timezone_set('Asia/Shanghai'); //$rfc822 = 'Mon, 16 Aug 2010 00:11:49 GMT';    //$i = date('Y-m-d H:i:s', strtotime($rfc822));    //echo $i;?> </body></html> 
 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表