{"id":65,"date":"2013-06-23T07:19:54","date_gmt":"2013-06-22T22:19:54","guid":{"rendered":"http:\/\/www.ranran.mydns.jp\/blog\/?p=65"},"modified":"2013-07-03T03:19:51","modified_gmt":"2013-07-02T18:19:51","slug":"rss%e3%83%aa%e3%83%bc%e3%83%80%e3%83%bc%e3%82%92%e4%bd%9c%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b","status":"publish","type":"post","link":"http:\/\/www.ranran.mydns.jp\/blog\/?p=65","title":{"rendered":"RSS\u30ea\u30fc\u30c0\u30fc\u3092\u4f5c\u3063\u3066\u307f\u308b"},"content":{"rendered":"<p>\u30d6\u30ed\u30b0\u3084\u30cb\u30e5\u30fc\u30b9\u306a\u3069\u306e\u66f4\u65b0\u60c5\u5831\u3092\u914d\u4fe1\u3059\u308b\u305f\u3081\u306b\u7528\u3044\u3089\u308c\u308bRSS<br \/>\n\u3053\u308c\u3092\u5229\u7528\u3057\u3066\u8907\u6570\u306e\u30b5\u30a4\u30c8\u306e\u60c5\u5831\u3092\u53d6\u5f97\u8868\u793a\u3057\u3066\u3044\u308b\u306e\u304c<strong>\u30a2\u30f3\u30c6\u30ca\u30b5\u30a4\u30c8<\/strong>\u3067\u3059\u3002<br \/>\n\u4eca\u56de\u3075\u3068\u601d\u3044\u7acb\u3063\u3066\u3053\u306e\u30a2\u30f3\u30c6\u30ca\u30b5\u30a4\u30c8\u3092\u4f5c\u308b\u3053\u3068\u306b\u3057\u305f\u306e\u3067\u6570\u56de\u306b\u5206\u3051\u3066\u4f5c\u6210\u307e\u3067\u306e\u9053\u306e\u308a\u3092\u3064\u3089\u3064\u3089\u3068\u3064\u3065\u3063\u3066\u884c\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u307e\u305a\u306fRSS\u3092\u89e3\u6790\u3059\u308b\u4ed5\u7d44\u307f\u304c\u5fc5\u8981\u306a\u306e\u3067\u3059\u304c\u30b0\u30b0\u3063\u3066\u898b\u3064\u304b\u308b\u30bd\u30fc\u30b9\u306f\u62e1\u5f35\u30e2\u30b8\u30e5\u30fc\u30eb\u306ecurl\u3092\u5229\u7528\u3057\u3066\u3044\u308b\u3082\u306e\u3070\u304b\u308a<br \/>\n\u57fa\u672c\u7684\u306b\u62e1\u5f35\u30e2\u30b8\u30e5\u30fc\u30eb\u306f\u4f7f\u3044\u305f\u304f\u306a\u3044\u306e\u3067\u81ea\u529b\u3067\u4f5c\u3063\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u305f\u3002<\/p>\n<p>\u30fbrssLoader.php<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n\r\nrequire_once __DIR__.&quot;\/channelBean.php&quot;;\r\nrequire_once __DIR__.&quot;\/itemBean.php&quot;;\r\nrequire_once __DIR__.&quot;\/rssException.php&quot;;\r\nrequire_once __DIR__.&quot;\/lib\/httpConnecter.php&quot;;\r\nrequire_once __DIR__.&quot;\/lib\/xmlLoader.php&quot;;\r\n\r\nclass rssLoader {\r\n\r\n\tconst VERSION_1 = 1;\r\n\tconst VERSION_2 = 2;\r\n\r\n\tconst VERSION_ALL = 0;\r\n\r\n\tpublic function __construct() {\r\n\t}\r\n\r\n\tpublic function __destruct() {\r\n\t}\r\n\r\n\t\/**\r\n\t * RSS\u3092\u8aad\u307f\u8fbc\u307fchannelBean\u3067\u53d6\u5f97\r\n\t *\r\n\t * @param int $version \u5bfe\u8c61RSS\u30d0\u30fc\u30b8\u30e7\u30f3\u6307\u5b9a\r\n     *                    \u5168\u30d0\u30fc\u30b8\u30e7\u30f3\u306eRSS  : rssLoader::VERSION_ALL\r\n     *                    \u30d0\u30fc\u30b8\u30e7\u30f31.0\u306eRSS : rssLoader::VERSION_1\r\n     *                    \u30d0\u30fc\u30b8\u30e7\u30f32.0\u306eRSS : rssLoader::VERSION_2\r\n\t *\r\n\t *\/\r\n\tpublic function loadRss($path, $version = self::VERSION_ALL) {\r\n\r\n\t\t\/**\r\n\t\t * RSS\u3092\u53d6\u5f97\r\n\t\t *\/\r\n\t\t$http = new httpConnecter();\r\n\t\t$http-&gt;connect($path);\r\n\t\t$rssStr = $http-&gt;loadText();\r\n\t\tif($rssStr === &quot;&quot;) {\r\n\r\n\t\t\t\/\/ \u53d6\u5f97\u3067\u304d\u306a\u3051\u308c\u3070\u30a8\u30e9\u30fc\r\n\t\t\tthrow rssException::notRss(&quot;RSS\u30d5\u30a1\u30a4\u30eb\u306e\u53d6\u5f97\u304c\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002&quot;);\r\n\t\t}\r\n\r\n\t\t\/**\r\n\t\t * RSS\u3092\u89e3\u6790\r\n\t\t *\/\r\n\t\t$xml = new xmlLoader();\r\n\t\t$rssDom = $xml-&gt;parsor($rssStr);\r\n\r\n\t\t$channelBean = new channelBean();\r\n\r\n\t\t$channelBean-&gt;encoding = &quot;UTF-8&quot;;\r\n\r\n\t\t\/\/ rss1.0\r\n\t\tif(isset($rssDom-&gt;attributes()-&gt;version) == false) {\r\n\t\t\t$channelBean-&gt;rssVersion = self::VERSION_1;\r\n\t\t\t$channelBean-&gt;rssUrl = $rssDom-&gt;channel-&gt;link;\r\n\r\n\t\t\tif($version != self::VERSION_1 &amp;&amp; $version != self::VERSION_ALL) {\r\n\r\n\t\t\t\tthrow rssException::notMatchVersion(&quot;\u3053\u306eRSS\u306fVertion1.0\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002&quot;);\r\n\t\t\t}\r\n\t\t}\r\n\t\t\/\/ rss2.0\r\n\t\telse if($rssDom-&gt;attributes()-&gt;version == 2) {\r\n\r\n\t\t\t$channelBean-&gt;rssVersion = self::VERSION_2;\r\n\t\t\t$channelBean-&gt;rssUrl = $rssDom-&gt;channel-&gt;link;\r\n\r\n\t\t\tif($version != self::VERSION_2 &amp;&amp; $version != self::VERSION_ALL) {\r\n\r\n\t\t\t\tthrow rssException::notMatchVersion(&quot;\u3053\u306eRSS\u306fVertion2.0\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002&quot;);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t\/\/ RSS\u306e\u672c\u4f53\u60c5\u5831\u3092\u53d6\u5f97\r\n\t\tif(isset($rssDom-&gt;channel-&gt;title)) {\r\n\t\t\t$channelBean-&gt;title = $rssDom-&gt;channel-&gt;title;\r\n\t\t}\r\n\t\tif(isset($rssDom-&gt;channel-&gt;link)) {\r\n\t\t\t$channelBean-&gt;link = $rssDom-&gt;channel-&gt;link;\r\n\t\t}\r\n\t\tif(isset($rssDom-&gt;channel-&gt;description)) {\r\n\t\t\t$channelBean-&gt;description = $rssDom-&gt;channel-&gt;description;\r\n\t\t}\r\n\t\t\/\/ dc\u306e\u8981\u7d20\u3092\u53d6\u5f97\r\n\t\t$dc = $rssDom-&gt;channel-&gt;children('http:\/\/purl.org\/dc\/elements\/1.1\/');\r\n\t\tif(isset($dc-&gt;date)) {\r\n\t\t\t$channelBean-&gt;date = $dc-&gt;date;\r\n\t\t}\r\n\t\tif(isset($dc-&gt;language)) {\r\n\t\t\t$channelBean-&gt;language = $dc-&gt;language;\r\n\t\t}\r\n\t\tif(isset($dc-&gt;creator)) {\r\n\t\t\t$channelBean-&gt;creator = $dc-&gt;creator;\r\n\t\t}\r\n\r\n\t\t\/\/ \u5404\u8a18\u4e8b\u3092\u53d6\u5f97\u3059\u308b\r\n\t\tforeach($rssDom-&gt;item as $item) {\r\n\r\n\t\t\t$itemBean = new itemBean();\r\n\r\n\t\t\tif(isset($item-&gt;title)) {\r\n\t\t\t\t$itemBean-&gt;title = $item-&gt;title;\r\n\t\t\t}\r\n\t\t\tif(isset($item-&gt;link)) {\r\n\t\t\t\t$itemBean-&gt;link = $item-&gt;link;\r\n\t\t\t}\r\n\t\t\tif(isset($item-&gt;description)) {\r\n\t\t\t\t$itemBean-&gt;description = $item-&gt;description;\r\n\t\t\t}\r\n\t\t\tif(isset($item-&gt;category)) {\r\n\t\t\t\t$itemBean-&gt;category = $item-&gt;category;\r\n\t\t\t}\r\n\t\t\tif(isset($item-&gt;pubDate)) {\r\n\t\t\t\t$itemBean-&gt;date = $item-&gt;date;\r\n\t\t\t}\r\n\t\t\t\/\/ dc\u306e\u8981\u7d20\u3092\u53d6\u5f97\r\n\t\t\t$dc = $item-&gt;children('http:\/\/purl.org\/dc\/elements\/1.1\/');\r\n\t\t\tif(isset($dc-&gt;date)) {\r\n\t\t\t\t$itemBean-&gt;date = $dc-&gt;date;\r\n\t\t\t}\r\n\t\t\tif(isset($dc-&gt;subject)) {\r\n\t\t\t\t$itemBean-&gt;category = $dc-&gt;subject;\r\n\t\t\t}\r\n\t\t\tif(isset($dc-&gt;creator)) {\r\n\t\t\t\t$itemBean-&gt;creator = $dc-&gt;creator;\r\n\t\t\t}\r\n\r\n\t\t\tarray_push($channelBean-&gt;itemList, $itemBean);\r\n\t\t}\r\n\r\n\t\treturn $channelBean;\r\n\t}\r\n}\r\n<\/pre>\n<p>rssLoader\u3067\u89e3\u6790\u3059\u308b\u3068channelBean\u30af\u30e9\u30b9\u304c\u8fd4\u5374\u3055\u308c\u308b\u3002<br \/>\n\u3053\u306echannelBean\u30af\u30e9\u30b9\u5185\u90e8\u306bitemBean\u306e\u30ea\u30b9\u30c8\u304c\u3042\u308a\u305d\u3053\u306b\u500b\u3005\u306e\u8a18\u4e8b\u306e\u30c7\u30fc\u30bf\u304c\u3042\u308b\u3068\u3044\u3063\u305f\u611f\u3058<br \/>\nitemBean\u304cchannelBean\u306e\u5185\u90e8\u306b\u3042\u308b\u306e\u306fRSS2.0\u3067\u306fchannel\u30bf\u30b0\u306e\u5185\u90e8\u306bitem\u30bf\u30b0\u304c\u3042\u308b\u304b\u3089\u3068\u3044\u3063\u305f\u7406\u7531\u304b\u3089<\/p>\n<p>\u4f7f\u3044\u65b9\u306f\u4ee5\u4e0b<br \/>\n\u30fbrssTest.php<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n\r\nrequire_once &quot;rssLoader.php&quot;;\r\n\r\n$rssLoader = new rssLoader();\r\ntry {\r\n\t$channel = $rssLoader-&gt;loadRss(&quot;http:\/\/watch2ch.2chblog.jp\/index.rdf&quot;);\/\/ \u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u4e0a\u306e\u30d5\u30a1\u30a4\u30eb\u306e\u5834\u5408\r\n\t\/\/$channel = $rssLoader-&gt;loadRss(&quot;\/var\/www\/html\/rss.rdf&quot;);\/\/ \u30ed\u30fc\u30ab\u30eb\u30d5\u30a1\u30a4\u30eb\u306e\u5834\u5408\r\n} catch (Exception $e) {\r\n\r\n\techo $e-&gt;getMessage();\r\n}\r\n\r\n?&gt;\r\n&lt;html lang=&quot;ja&quot;&gt;\r\n\t&lt;head&gt;\r\n\t\t&lt;meta charset=&quot;utf-8&quot; \/&gt;\r\n\t\t&lt;title&gt;RSS&lt;\/title&gt;\r\n\t&lt;\/head&gt;\r\n\r\n\t&lt;body&gt;\r\n\t\t&lt;h2&gt;&lt;?=$channel-&gt;title ?&gt;&lt;\/h2&gt;\r\n\t\t&lt;table border=&quot;1&quot;&gt;\r\n\t\t\t&lt;tr&gt;\r\n\t\t\t\t&lt;th&gt;\u30bf\u30a4\u30c8\u30eb\u4e00\u89a7&lt;\/th&gt;\r\n\t\t\t\t&lt;th&gt;\u8a18\u4e8b&lt;\/th&gt;\r\n\t\t\t\t&lt;th&gt;\u4f5c\u6210\u65e5&lt;\/th&gt;\r\n\t\t\t&lt;\/tr&gt;\r\n\t\t\t&lt;?php foreach($channel-&gt;itemList as $item): ?&gt;\r\n\t\t\t&lt;tr&gt;\r\n\t\t\t\t&lt;td&gt;&lt;?=$item-&gt;title ?&gt;&lt;\/td&gt;\r\n\t\t\t\t&lt;td&gt;&lt;?=$item-&gt;date ?&gt;&lt;\/td&gt;\r\n\t\t\t&lt;\/tr&gt;\r\n\t\t\t&lt;?php endforeach; ?&gt;\r\n\t\t&lt;\/table&gt;\r\n\t&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u306f\u3053\u3061\u3089\uff1a[download id=&#8221;1&#8243;]<\/p>\n<p>\u3053\u308c\u3067RSS\u3092\u8aad\u307f\u8fbc\u3093\u3067\u8a18\u4e8b\u60c5\u5831\u3092\u53d6\u308a\u51fa\u3059\u3053\u3068\u306f\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u6b21\u56de\u306b\u7d9a\u304d\u307e\u3059\u3002<\/p>\n<p><strong>\u8ffd\u8a18<\/strong><br \/>\n\u3053\u306erssLoader\u306b\u306fRSS2.0\u304c\u8aad\u307f\u8fbc\u3081\u306a\u3044\u30d0\u30b0\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u4fee\u6b63\u7248\u306f\u5f8c\u65e5\u5225\u306e\u8a18\u4e8b\u306b\u3066\u63b2\u8f09\u3044\u305f\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30d6\u30ed\u30b0\u3084\u30cb\u30e5\u30fc\u30b9\u306a\u3069\u306e\u66f4\u65b0\u60c5\u5831\u3092\u914d\u4fe1\u3059\u308b\u305f\u3081\u306b\u7528\u3044\u3089\u308c\u308bRSS \u3053\u308c\u3092\u5229\u7528\u3057\u3066\u8907\u6570\u306e\u30b5\u30a4\u30c8\u306e\u60c5\u5831\u3092\u53d6\u5f97\u8868\u793a\u3057\u3066\u3044\u308b\u306e\u304c\u30a2\u30f3\u30c6\u30ca\u30b5\u30a4\u30c8\u3067\u3059\u3002 \u4eca\u56de\u3075\u3068\u601d\u3044\u7acb\u3063\u3066\u3053\u306e\u30a2\u30f3\u30c6\u30ca\u30b5\u30a4\u30c8\u3092\u4f5c\u308b\u3053\u3068\u306b\u3057\u305f\u306e\u3067\u6570\u56de\u306b\u5206\u3051\u3066\u4f5c\u6210\u307e\u3067\u306e\u9053 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,9,8],"tags":[],"class_list":["post-65","post","type-post","status-publish","format-standard","hentry","category-php","category-9","category-8"],"_links":{"self":[{"href":"http:\/\/www.ranran.mydns.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ranran.mydns.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ranran.mydns.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ranran.mydns.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ranran.mydns.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=65"}],"version-history":[{"count":13,"href":"http:\/\/www.ranran.mydns.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":76,"href":"http:\/\/www.ranran.mydns.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/65\/revisions\/76"}],"wp:attachment":[{"href":"http:\/\/www.ranran.mydns.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ranran.mydns.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ranran.mydns.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}