PHP - RSS builder

前端 未结 6 1621
天命终不由人
天命终不由人 2021-01-22 04:25

I have a old website that generate its own RSS everytime a new post is created. Everything worked when I was on a server with PHP 4 but now that the host change to PHP 5, I alwa

6条回答
  •  感情败类
    2021-01-22 04:47

    At swcombine.com we use Feedcreator. Use that one and your problem will be gone. :)

    Here is the PHP code to use it once installed:

    function feed_simnews() {
        $objRSS = new UniversalFeedCreator();
        $objRSS->title = 'My News';
        $objRSS->link = 'http://link.to/news.php';
        $objRSS->description = 'daily news from me';
        $objRSS->xsl = 'http://link.to/feeds/feedxsl.xsl';
        $objRSS->language = 'en';
        $objRSS->copyright = 'Copyright: Mine!';
        $objRSS->webmaster = 'webmaster@somewhere.com';
        $objRSS->syndicationURL = 'http://link.to/news/simnews.php';
        $objRSS->ttl = 180;
    
        $objImage = new FeedImage();
        $objImage->title = 'my logo';
        $objImage->url = 'http://link.to/feeds/logo.jpg';
        $objImage->link = 'http://link.to';
        $objImage->description = 'Feed provided by link.to. Click to visit.';
        $objImage->width = 120;
        $objImage->height = 60;
        $objRSS->image = $objImage;
    
        //Function retrieving an array of your news from date start to last week
        $colNews = getYourNews(array('start_date' => 'Last week'));
    
        foreach($colNews as $p) {
            $objItem = new FeedItem();
            $objItem->title = $p->title;
            $objItem->description = $p->body;
            $objItem->link = $p->link;
            $objItem->date = $p->date;
            $objItem->author = $p->author;
            $objItem->guid = $p->guid;
    
            $objRSS->addItem($objItem);
        }
    
        $objRSS->saveFeed('RSS2.0', 'http://link.to/feeds/news.xml', false);
    };
    

    Quite KISS. :)

提交回复
热议问题