我博客的rss源:http://feed.cnblogs.com/blog/u/127781/rss
RSS的作用是什么?
比如你訂閱了我的rss,那么如果我有文章發布,你就能及時看到更新,提供RSS輸出,有利於讓用戶獲取網站內容的最新更新。
如何訂閱RSS?
在rss閱讀器、QQ訂閱等建立rss鏈接即可及時看到對應網站的更新。
怎么制作RSS源?
RSS是一種XML格式的文檔,制作RSS的過程就是把信息生成xml文件的過程。
1、在這里推薦一個在線生成RSS的網站,www.xml-sitemaps.com
2、也可以采集信息生成xml:phpQuery簡單采集實例
3、跟數據庫結合,查詢數據生成xml格式的文件
一個簡單的xml文檔:
<?xml version="1.0" encoding="gb2312"?> <rss version="2.0"> <channel> <title>tinyphp的博客</title> <link>http://www.cnblogs.com/tinyphp</link> <description>tinyphp web page</description> <item> <title>文章標題一</title> <link>http://www.cnblogs.com/tinyphp/archive/2013/04/19/3030233.html</link> <description>文章內容一</description> </item> <item> <title>文章標題二</title> <link>http://www.cnblogs.com/tinyphp/archive/2013/04/18/3029193.html</link> <description>文章內容二</description> </item> </channel> </rss>
php生成xml簡單實例:
<?php // 創建xml $dom = new DOMDocument("1.0","gb2312"); header("Content-Type: text/plain"); // 創建根節點 $root = $dom->createElement("channel"); $dom->appendChild($root); // 創建子節點 $item = $dom->createElement("item"); $root->appendChild($item); // 創建標題節點 $text = $dom->createElement("title"); $item->appendChild($text); // 創建標題內容 $titletext = $dom->createTextNode("這是標題內容"); $text->appendChild($titletext); //創建節點內容 $content = $dom->createElement("description"); $item->appendChild($content); // 創建內容 $contenttext = $dom->createTextNode("這是內容"); $content->appendChild($contenttext); // 創建另外一元素 $item = $dom->createElement("item"); $root->appendChild($item); // 創建另外一個文本 $text = $dom->createTextNode("title"); $item->appendChild($text); // 保存xml echo $dom->saveXML(); ?>
預覽效果:
改裝一下上面的例子:PHP+Mysql
<? include_once 'comm/conn.php'; $sql="select * from article limit 5"; $query=mysql_query($sql); // 創建xml $dom = new DOMDocument("1.0","gb2312"); header("Content-Type: text/plain"); // 創建根節點 $root = $dom->createElement("channel"); $dom->appendChild($root); while($row=mysql_fetch_array($query)){ // 創建子節點 $item = $dom->createElement("item"); $root->appendChild($item); // 創建標題節點 $text = $dom->createElement("title"); $item->appendChild($text); // 創建標題內容 $titletext = $dom->createTextNode("".$row['title'].""); $text->appendChild($titletext); //創建節點內容 $content = $dom->createElement("description"); $item->appendChild($content); // 創建內容 $contenttext = $dom->createTextNode("".$row['content'].""); $content->appendChild($contenttext); } // 保存xml echo $dom->saveXML(); ?>
相關文章: