从站点创建RSS源

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从站点创建RSS源相关的知识,希望对你有一定的参考价值。

If you syndicate your content with an RSS feed it can help to drive additional traffic to the content pages.
  1. // your DB connection goes here
  2. define('LINKBASE','http://yoursite.com/');
  3. $sql=$yourDB->query("SELECT pageTitle,pageLink,pageDesc,pageDate FROM pageTab ORDER BY pageDate DESC LIMIT 10");
  4. $cnt=$sql->rowCount();
  5. // NOW WE NEED TO DO THE HEADING FOR THE FEED
  6. $feedMainLink=LINKBASE.'feedname.xml';
  7. $mainDate=date("D, d M Y H:i:s O"); // format the date to the rss 2.0 standard
  8. $rssfeed='<?xml version="1.0" encoding="UTF-8"?>';
  9. // WE'LL USE HEREDOC TO BUILD THE HEADING LINES
  10. $rssfeed.=<<<HEAD
  11. <rss version="2.0">
  12. <channel>
  13. <title>TITLE of the FEED</title>
  14. <link>$feedMainLink</link>
  15. <description>A selection of the latest articles, editorials and script snippets</description>
  16. <pubDate>$mainDate</pubDate>
  17. HEAD;
  18. // NOW WE CAN LOOP OUT THE ITEMS
  19. $rowBlock=$sql->fetch(PDO::FETCH_ASSOC);
  20. for ($i=0;$i<$cnt;$i++);
  21. {
  22. $row=$rowBlock[$i];
  23. $PgLink=LINKBASE.$row['pageLink'];
  24. $pubDate=date("D, d M Y H:i:s O", strtotime($row['pageDate']));
  25. $rssfeed.=<<<ITEM
  26. <item>
  27. <title>{$row['pageTitle']}</title>
  28. <description>{$row['pageDesc']}...</description>
  29. <link>$pageLink</link>
  30. <pubDate>$pubDate</pubDate>
  31. </item>
  32. ITEM;
  33. }
  34. }
  35. $rssfeed .= '</channel>';
  36. $rssfeed .= '</rss>';
  37. file_put_contents('feedname.xml', $rssfeed);

以上是关于从站点创建RSS源的主要内容,如果未能解决你的问题,请参考以下文章

在 PHP 中解析 RSS2

将 RSS 提要发送到 phpMyAdmin

百科知识 什么是RSS订阅

使用Spring启动的RSS提要

用于静态站点的RSS

curl:由于 CloudFlare,无法从网站获取 RSS