RSS是在线共享内容的一种简易方式(也叫聚合内容,Really Simple Syndication)。通常在时效性比较强的内容上使用RSS
我们可以订阅rrs到自己的网站,一般是xml格式的,我们可以看一下他的格式
输入:http://rss.sina.com.cn/news/world/focus16.xml 查看页面源码就可以看到RSS的结构。
下面我们写一个rss.php来读取这个xml,从而获取这上面的文章:<?php header("Content-Type:text/html;charset=utf-8"); ?>
<html>
<head>
<title>XML</title>
</head>
<body>
<?php
$dom = simplexml_load_file("http://rss.sina.com.cn/news/world/focus15.xml");
//var_dump($dom);
?>
<h2>The example of RSS</h2>
<ul>
<?php
foreach($dom->channel->item as $item)
{
print("<li>");
print("<a href='$item->link'>");
print($item->title);
print("</a>");
print("</li>");
}
?>
</ul>
</body>
</html>
注意这个函数:simplexml_load_file() ; 它既可以读本地的xml文件,也可以读网络上的xml,这样就可以显示在自己的网站上了