{"id":158,"date":"2009-12-05T00:51:14","date_gmt":"2009-12-04T15:51:14","guid":{"rendered":"http:\/\/yamazon.org\/?p=158"},"modified":"2009-12-05T00:51:14","modified_gmt":"2009-12-04T15:51:14","slug":"php-%e3%81%a7%e3%81%ae-simplexml-%e5%87%a6%e7%90%86%ef%bc%9e%ef%bc%9erss%e5%8f%96%e5%be%97","status":"publish","type":"post","link":"https:\/\/apr20.net\/?p=158","title":{"rendered":"PHP \u3067\u306e SimpleXML \u51e6\u7406\uff1e\uff1eRSS\u53d6\u5f97"},"content":{"rendered":"<p>php\u3067rss\u306e\u60c5\u5831\u3092\u629c\u304d\u51fa\u3057\u305f\u3044\u5834\u5408\u306f\u3001title\u3084link\u306e\u8981\u7d20\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u629c\u304d\u51fa\u305b\u307e\u3059\u3002<\/p>\n<pre><span style=\"color: #008000;\">&lt;?php \/\/ Load and parse the XML document\n$rss =  simplexml_load_file('http:\/\/partners.userland.com\/nytRss\/nytHomepage.xml');\n$title =  $rss-&gt;channel-&gt;title;\n?&gt;\n<!--more--><\/span><span style=\"color: #008000;\">\n&lt;html xml:lang=\"en\" lang=\"en\"&gt;\n&lt;head&gt;\n  &lt;title&gt;&lt;?php echo $title; ?&gt;&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n\n&lt;h1&gt;&lt;?php echo $title; ?&gt;&lt;\/h1&gt;\n\n&lt;?php\n\/\/ Here we'll put a loop to include each item's title and description\nforeach ($rss-&gt;channel-&gt;item as $item) {\n  echo \"&lt;h2&gt;&lt;a href='\" . $item-&gt;link . \"'&gt;\" . $item-&gt;title . \"&lt;\/a&gt;&lt;\/h2&gt;\";\n  echo \"&lt;p&gt;\" . $item-&gt;description . \"&lt;\/p&gt;\";\n}\n?&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;<\/span><\/pre>\n<p>\u6700\u521d\u306b\u66f8\u3044\u305f\u901a\u308a\u3001\u4e0a\u8a18\u3067title\u306a\u3069\u306f\u53d6\u5f97\u51fa\u6765\u307e\u3059\u304c\u3001&lt;content:encoded&gt;\u306a\u3069\u3001<\/p>\n<pre id=\"line16\"><strong><span style=\"color: #ff0000;\">&lt;![CDATA[<\/span><\/strong><\/pre>\n<p>\u304c\u542b\u307e\u308c\u308b\u7b87\u6240\u304c\u53d6\u5f97\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>\u305d\u3053\u3067\u3001\u300c<a title=\"\u3053\u306e\u30da\u30fc\u30b8\u3092\u691c\u7d22\" href=\"http:\/\/www.hyuki.com\/yukiwiki\/wiki.cgi?MagpieRSS\" target=\"_blank\">MagpieRSS<\/a> &#8211; PHP \u3067\u4f7f\u3048\u308b RSS \u30d1\u30fc\u30b5\u30fc\u3002\u300d\u3092\u53c2\u8003\u306bMagpieRSS\u3068\u3044\u3046\u3082\u306e\u3092\u5229\u7528\u3057\u307e\u3057\u305f\u3002<\/p>\n<h3>\u4f7f\u3044\u65b9<\/h3>\n<p>index.php \u306b <a href=\"http:\/\/www.hyuki.com\/yukiwiki\/wiki.cgi?RssPage\">http:\/\/yamazon.org\/feed<\/a> \u306eRSS\u3092\u57cb\u3081\u8fbc\u3080\u3068\u3057\u3066\u624b\u9806\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\n<ul>\n<li> <a href=\"http:\/\/magpierss.sourceforge.net\/\">http:\/\/magpierss.sourceforge.net\/<\/a> \u3067 MagpieRSS (magpierss-0.3.tar.gz) \u3092\u5165\u624b\u3002<\/li>\n<li> magpierss-0.3.tar.gz \u3092\u89e3\u51cd\u3002<\/li>\n<li> \u62e1\u5f35\u5b50\u304c .inc \u306e\u30d5\u30a1\u30a4\u30eb\u3068 extlib \u30d5\u30a9\u30eb\u30c0\u3092 index.php \u3068\u540c\u3058\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3002<\/li>\n<li> \u540c\u3058\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\uff08\u30b5\u30fc\u30d0\u4e0a\uff09\u306e\u4e0b\u306b cache \u3068\u3044\u3046\u540d\u524d\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u308b\u3002<\/li>\n<li> index.php \u306e\u4e2d\u306e\u30d8\u30c3\u30c9\u30e9\u30a4\u30f3\u3092\u57cb\u3081\u8fbc\u307f\u305f\u3044\u4f4d\u7f6e\u306b\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u633f\u5165\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u306e\u8a2d\u5b9a\u304c\u5b8c\u4e86\u3057\u305f\u3089\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30bd\u30fc\u30b9\u3067\u629c\u304d\u51fa\u3057\u307e\u3059\u3002<\/p>\n<pre><span style=\"color: #008000;\">&lt;?php\ninclude('rss_fetch.inc');<\/span>\n\n<span style=\"color: #008000;\">$url = \"http:\/\/yamazon.org\/feed\";\n$rss = fetch_rss($url);<\/span>\n\n<span style=\"color: #008000;\">if($rss){\n$items = $rss-&gt;items;\nforeach($items as $item){\n$content = $item[\"content\"][\"encoded\"];\n$content = mb_convert_encoding($content, \"UTF-8\", \"auto\");\necho $content;\n}\n}else{\necho \"file not found.\";\n}\n?&gt;<\/span><\/pre>\n<p>\u3053\u308c\u3067\u3001&lt;content:encoded&gt;\u304c\u629c\u304d\u51fa\u305b\u307e\u3057\u305f\u304c\u3001\u6587\u5b57\u5316\u3051\u3057\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>mb_convert_encoding\u3067\u30a8\u30f3\u30b3\u30fc\u30c9\u3057\u3066\u3082\u6587\u5b57\u5316\u3051\u306e\u307e\u307e\u30fb\u30fb\u30fb\u3002\uff08\u3069\u3046\u3084\u3089ASCII\u306b\u5909\u63db\u3055\u308c\u3066\u3044\u308b\u6a21\u69d8\uff1f\uff09<\/p>\n<p>\u6587\u5b57\u5316\u3051\u306b\u3064\u3044\u3066\u306f\u89e3\u6c7a\u6b21\u7b2c\u3001\u5831\u544a\u3057\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h3>&lt;\u8ffd\u8a18&gt;<\/h3>\n<h3><span style=\"color: #3366ff;\">\u6587\u5b57\u5316\u3051\u306e\u4ef6\u304c\u89e3\u6c7a\u3057\u305f\u306e\u3067\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/span><\/h3>\n<h2>\uff08Jcode.php\u3092\u4f7f\u3046\u65b9\u6cd5 &#8211; mb_convert_encoding\u304c\u4f7f\u3048\u306a\u3044\u5834\u5408\u306e\u89e3\u6c7a\u6cd5\u305d\u306e1\uff09<\/h2>\n<ul>\n<li> <a href=\"http:\/\/www.spencernetwork.org\/jcode\/\">http:\/\/www.spencernetwork.org\/jcode\/<\/a> \u3067Jcode.php\uff08jcode_1.34.zip\uff09\u3092\u5165\u624b\u3002<\/li>\n<li> jcode_1.34.zip \u3092\u89e3\u51cd\u3002<\/li>\n<li> jcode.phps \u3092 jcode.php \u306b\u62e1\u5f35\u5b50\u3092\u5909\u3048\u305f\u5f8c\u3001readme.txt \u4ee5\u5916\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u540c\u3058\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3002\uff08jcode.php \u3068 code_table.ucs2jis \u306e\u307f\u3067\u3082\u53ef\uff09<\/li>\n<li> \u30b3\u30fc\u30c9\u3092\u4ee5\u4e0b\u306e\u69d8\u306b\u5909\u66f4\u3002<\/li>\n<\/ul>\n<pre> <span style=\"color: #008000;\">&lt;?php\n\/\/MagpieRSS\n include('rss_fetch.inc');\n require_once 'code_table.ucs2jis';\n require_once 'jcode.php';\n\n $url = $search_domain;\n $rss = fetch_rss($url);\n\n $title = $rss-&gt;channel[\"title\"];\n\u00a0\/\/JcodeConvert($str, $from, $to) 0:PASS\uff08\u7121\u5909\u63db\uff091:EUC-JP 2:Shift_JIS 3:ISO-2022-JP(JIS) 4:UTF-8\n\u00a0\/\/\u4eca\u56de\u306f\u5909\u63db\u5143\u304cEUC-JP\u3060\u3063\u305f\u306e\u3067\u3001PASS,4 \u3067UTF-8\u306b\u5909\u63db\u3057\u3066\u307e\u3059\u3002\n $title = JcodeConvert($title, 0, 4);\n\n echo $title;\n\n if($rss){\n $items = $rss-&gt;items;\n foreach($items as $item){\n $content = $item[\"content\"][\"encoded\"];\n $url\u00a0\u00a0 = $item[\"link\"];\n\n $content = JcodeConvert($content, 0, 4);\n echo $url;\n echo $content;\n\n }\n }else{\n echo \"file not found.\";\n }\n\/\/MagpieRSS\n ?&gt;<\/span><\/pre>\n<p>\u79c1\u306e\u5834\u5408\u306f\u4ee5\u4e0a\u3067\u3001\u6587\u5b57\u5316\u3051\u3082\u306a\u304f<strong><span style=\"color: #ff0000;\"> &lt;![CDATA[ <\/span><\/strong>\u304c\u542b\u307e\u308c\u308b\u8981\u7d20\u3082\u5168\u3066\u53d6\u5f97\u51fa\u6765\u307e\u3057\u305f\u3002<\/p>\n<p>RSS\u3092\u53d6\u5f97\u3059\u308b\u3001\u305d\u306e\u4ed6\u306e\u65b9\u6cd5\u3068\u3057\u3066<\/p>\n<h3><a title=\"Permanent Link to XML::FeedPP\u3067\u3001content:encoded\u306a\u3069\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\" rel=\"bookmark\" href=\"http:\/\/pct.lanlan.biz\/2009\/11\/23\/xmlfeedpp%e3%81%a7%e3%80%81contentencoded%e3%81%aa%e3%81%a9%e3%82%92%e5%8f%96%e5%be%97%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95\/\">XML::FeedPP\u3067\u3001content:encoded\u306a\u3069\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5<\/a><\/h3>\n<p>\u306a\u3069\u3082\u3042\u308b\u3088\u3046\u3067\u3059\u3002<br \/>\n<strong><span style=\"color: #ff0000;\"> <\/span><\/strong><\/p>\n<div id=\"_mcePaste\" style=\"overflow: hidden; position: absolute; left: -10000px; top: 1059px; width: 1px; height: 1px;\">\n<pre class=\"verbatim-hard\">\/\/JcodeConvert($str, $from, $to) 0:PASS\uff08\u7121\u5909\u63db\uff091:EUC-JP 2:Shift_JIS 3:ISO-2022-JP(JIS) 4:UTF-8<\/pre>\n<\/div>\n<p>http:\/\/www.doyouphp.jp\/php5\/php5_simplexml.shtml<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php\u3067rss\u306e\u60c5\u5831\u3092\u629c\u304d\u51fa\u3057\u305f\u3044\u5834\u5408\u306f\u3001title\u3084link\u306e\u8981\u7d20\u306f\u4ee5\u4e0b\u306e\u901a\u308a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[104,139,195],"class_list":["post-158","post","type-post","status-publish","format-standard","hentry","category-old-blog","tag-magpierss","tag-rss","tag-xml"],"_links":{"self":[{"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=158"}],"version-history":[{"count":0,"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions"}],"wp:attachment":[{"href":"https:\/\/apr20.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}