XML_Feed_Parser 1.0.0ãªãªã¼ã¹
ä»ã¾ã§ã¯PEAR::XML_RSSã§ããããä»å¾ã¯ããã§ãããããï¼RSS0.9x/RSS1.x/RSS2.0/Atomã«å¯¾å¿ãã¦ããããã§ãã
ã¨ãããã¨ã§ãhttp://www.doyouphp.jp/sample/sample_xml_pear_rss.shtmlãå ãã¿ã«ï¼RSS1.0/2.0ã ãã§ããï¼ãã£ã¨è©¦ãã¦ã¿ã¾ããã以ä¸ã³ã¼ãã§ãï¼ææãã ãããï¼ã
XML_Feed_Parser is a parser for (the various) RSS and Atom format XML feeds. It attempts to provide a somewhat unified API while still allowing access to the full details of each feed type.
<?php require_once 'XML/Feed/Parser.php'; ?> <?php function buildFeedList($url) { $source = file_get_contents($url); try { $feed = new XML_Feed_Parser($source); } catch (Exception $e) { die($e->getMessage()); } $version = $feed ->version(); printf( '<h1><a href="%s">%s</a>ã®ãããã©ã¤ã³</h1>', $feed->link, mb_convert_encoding($feed->title, mb_internal_encoding(), 'auto') ); echo '<ul>'; foreach ($feed as $entry) { switch ($version) { case 'RSS 1.0': $dt = date('Y/m/d H:i',$entry->date); break; case 'RSS 2.0': $dt = date('Y/m/d H:i', $entry->pubDate); break; default: $dt = 'no data'; } printf( '<li>[%s] <a href="%s" title="%s">%s</a></li>', $dt, $entry->link, mb_convert_encoding($entry->title, mb_internal_encoding(), 'auto'), mb_convert_encoding($entry->title, mb_internal_encoding(), 'auto') ); } echo '</ul>'; echo '<hr/>'; } buildFeedList('http://d.hatena.ne.jp/shimooka/rss'); buildFeedList('http://www.phppro.jp/news/rss.php');
$entryï¼XML_Feed_Parser_xxxxElementã¯ã©ã¹ï¼ã«åfeedã®ãããã³ã°æ å ±ãæã£ã¦ãããããªã®ã§ãæ¥ä»ã¨ãã¯åãAPIã§åãåºããããªãã使ãæ¹ãããºã¤ã®ããªããã