2009-11-09 3 views
2

PHP에서 원자 피드를 만들려면 어떻게해야합니까?PHP 원자 피드 만들기

+3

연구를 수행 했습니까? 이것은 꽤보기 흉하지 않은 기사입니다. http://www.ibm.com/developerworks/opensource/library/x-phpatomfeed/index.html –

+0

그게 꼭 필요한 것입니다. – jkushner

답변

-2

위키 백과는 example of what an ATOM feed looks입니다.

을 아주 :이 스레드 우연히 발견 할 수 있습니다 누구를위한

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); 
    } 
} 
+0

사실상 아무 것도 벗어나지 못하고 있습니다! 항목 제목이나 설명에 리터럴 태그가 있으면 어떻게됩니까? 출력이 borked됩니다. 'O_O' –

2

업데이트 : 나는 매우 간단한 RSS 피드를 생성 할 오래 전에 쓴이 매우 기본 RSS 클래스를 수정하여 주시기 바랍니다 비슷한 질문은 The best PHP lib/class to generate RSS/Atom에서 물었고 좋은 lib/number의 추천으로 이어진다.