最简单的PHP读取RSS内容
我们可以读取csdn的PHP的发布最新信息..................
=============begin php code===================
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CSDN RSS-PHP信息</title>
<meta name="generator" content="editplus" />
<meta name="author" content="sjtprruy" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CSDN-rss最新消息</title>
</head>
<body>
<?php
$xmlfile = @fopen("http://forum.csdn.net/Rss/PHP/UnClosedList", "r");//参考http://forum.csdn.net/Rss/PHP/UnClosedList
if(!$xmlfile)
die("不能打开RSS文件,请稍候再刷新!");
$readfile = fread($xmlfile ,40000);
$searchfile = eregi("<item>(.*)</item>", $readfile ,$arrayreg);
$filechunks = explode("<item>", $arrayreg[0]);
$count = count($filechunks);
echo "<table bgcolor=\"#ffffff\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bordercolordark=\"#ffffff\"
bordercolorlight=\"#000000\">";
echo "<th colspan='3'>最新新闻</th>";
echo "<tr><td>标题</td><td>发布者</td><td>发布时间</td></tr>";
for($i=1 ; $i<=$count-1 ;$i++)
{
ereg("<title>(.*)</title>",$filechunks[$i], $title);//标题
ereg("<link>(.*)</link>",$filechunks[$i], $links);//链接网址
ereg("<author>(.*)</author>",$filechunks[$i],$author);//发布者
ereg("<pubDate>(.*)</pubDate>",$filechunks[$i],$pubDate);//发布时间
ereg("<description>(.*)</description",$filechunks[$i],$desc);//取内容部分
echo "<tr><td>";
echo "<a href =".$links[1]." title=".$desc[1].">".$title[1]."</a>";
echo "</td><td>";
echo $author[1];
echo "</td><td>";
echo $pubDate[1];
echo "</td></tr>";
}
echo "</table>";
?>
</body>
</html>
=============end php code===================
抓到rss内容基本完成。。。