【问题标题】:PHP Creating an atom feedPHP 创建一个原子提要
【发布时间】:2009-11-09 14:43:29
【问题描述】:

如何在 PHP 中创建原子提要?

【问题讨论】:

标签: php feed atom-feed


【解决方案1】:

任何可能偶然发现此线程的人的更新:

The best PHP lib/class to generate RSS/Atom 中提出了一个非常相似的问题,它导致了许多好的 lib/roll 您自己的建议。

【讨论】:

    【解决方案2】:

    使用library

    【讨论】:

      【解决方案3】:

      维基百科有一个example of what an ATOM feed looks 赞。随意修改我很久以前编写的这个非常基本的 RSS 类,以创建一个非常简单的 RSS 提要:

      class RSSFeed
      {       
          var $feedHeader;
          var $feedItems;
      
          /* Class Constructor */
          function RSSFeed()
          {
              //do some contruction
              $this->feedHeader = '';
              $this->feedItems = '';
          }
      
          function setFeedHeader($title, $link, $description, $copyright, $lastBuildDate, $ttl)
          {
              $this->feedHeader = '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel>';
              $this->feedHeader .= '<title>'.$title.'</title>';
              $this->feedHeader .= '<link>'.$link.'</link>';
              $this->feedHeader .= '<description>'.$description.'</description><copyright>'.$copyright.'</copyright>';
              $this->feedHeader .= '<language>en-GB</language><lastBuildDate>'.$lastBuildDate.' GMT</lastBuildDate><ttl>'.$ttl.'</ttl>';
          }
      
          function pushItem($title, $link, $description, $pubDateTime)
          {
              $item = '<item><title>' . htmlentities(stripslashes($title)) . '</title>';
              $item .= '<link>' . $link . '</link>';
              $item .= '<guid>' . $link . '</guid>';
              $item .= '<description>' . htmlentities(stripslashes($description)) . '</description>';
      
              $item .= '<pubDate>' . $pubDateTime . ' GMT</pubDate></item>';
      
              $this->feedItems = $item . $this->feedItems;
          }
      
          function writeOutFeed($path)
          {
              $file = fopen($path, "w");
              fputs($file, $this->feedHeader);
              fputs($file, $this->feedItems);
              fputs($file, '</channel></rss>');
              fclose($file);
          }
      }
      

      【讨论】:

      • 你几乎没有逃避任何事情!如果项目标题或描述中有文字标签怎么办?输出将被破坏。 O_O
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-26
      • 1970-01-01
      相关资源
      最近更新 更多