php 做的RSS采集
????? 之前一直想在自己的网站上加一些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><?php function 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>
?
立即学习“PHP免费学习笔记(深入)”;
?
立即学习“PHP免费学习笔记(深入)”;
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号