@blog.justoneplanet.info

日々勉強

ZendFramework Zend_Feed(フィード)

以下のようにフィードを取得することができる。

<?php
require_once 'Zend/Feed.php';

try{
    $feed = Zend_Feed::import('http://example.org/rss.xml');
}
catch(Zend_Feed_Exception $e){
    die('eror');
}
if(get_class($feed) === 'Zend_Feed_Rss'){
    $channel = array(
        'site_title' => $feed->title(),
        'site_url' => $feed->title(),
        'site_description' => $feed->description()
    );
    $entries = array();
    foreach($feed as $item){
        $entries[] = array(
            'article_title' => $item->title(),
            'article_category' => $item->category(),
            'article_author' => $item->creator(),
            'article_url' => $item->link(),
            'article_content' => $item->description(),
            'article_update' => $item->pubDate()
        );
    }
}
else{
    $channel = array(
        'site_title' => $feed->title(),
        'site_url' => $feed->link('alternate'),
        'site_description' => $feed->tagline()
    );
    $entries = array();
    foreach($feed as $item){
        $entries[] = array(
            'article_title' => $item->title(),
            'article_category' => $item->subject(),
            'article_author' => $item->author->name(),
            'article_url' => $item->link('alternate'),
            'article_content' => $item->content(),
            'article_update' => $item->modified()
        );
    }
}

コメントはまだありません»

No comments yet.

RSS feed for comments on this post.TrackBack URL

Leave a comment