日期:2014-05-17  浏览次数:20659 次

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>

?

?