{"id":173,"date":"2015-06-25T15:25:03","date_gmt":"2015-06-25T07:25:03","guid":{"rendered":"https:\/\/www.webteach.tw\/?p=173"},"modified":"2015-06-25T15:25:03","modified_gmt":"2015-06-25T07:25:03","slug":"php-rss-%e8%ae%80%e5%8f%96%e7%af%84%e4%be%8b-%e4%bb%a5%e9%99%a3%e5%88%97%e5%84%b2%e5%ad%98%e7%b5%90%e6%9e%9c","status":"publish","type":"post","link":"https:\/\/www.webteach.tw\/?p=173","title":{"rendered":"[ PHP ] &#8211; RSS \u8b80\u53d6\u7bc4\u4f8b \u4ee5\u9663\u5217\u5132\u5b58\u7d50\u679c"},"content":{"rendered":"<p>\t\t\t\t[php]<br \/>\n&lt;?php<br \/>\n\t$rss=&quot;http:\/\/www.cw.com.tw\/RSS\/industry.xml&quot;;\/\/rss \u7db2\u5740<br \/>\n\t$rssfeed =array();<br \/>\n\tarray_push($rssfeed,$rss);<br \/>\n\t\/\/\u8a2d\u7f6e\u7de8\u78bc\u70baUTF-8<br \/>\n\theader(&#8216;Content-Type:text\/html;charset= UTF-8&#8242;);<br \/>\n\tfor ($i = 0; $i &lt; sizeof($rssfeed); $i++) {\/\/\u5206\u89e3\u958b\u59cb<br \/>\n\t\t$buff = &quot;&quot;;<br \/>\n\t\t$rss_str = &quot;&quot;;<br \/>\n\t\t\/\/\u6253\u958brss\u5730\u5740\uff0c\u4e26\u8b80\u53d6\uff0c\u8b80\u53d6\u5931\u6557\u5247\u4e2d\u6b62<br \/>\n\t\t$fp = fopen($rssfeed[$i], &quot;r&quot;) or die(&quot;can not open $rssfeed&quot;);<br \/>\n\t\twhile (!feof($fp)) {<br \/>\n\t\t\t$buff .= fgets($fp, 4096);<br \/>\n\t\t}<br \/>\n\t\t\/\/\u95dc\u9589\u6587\u4ef6\u6253\u958b<br \/>\n\t\tfclose($fp);<br \/>\n\t\t\/\/\u5efa\u7acb\u4e00\u500b XML \u89e3\u6790\u5668<br \/>\n\t\t$parser = xml_parser_create();<br \/>\n\t\t\/\/xml_parser_set_option &#8212; \u70ba\u6307\u5b9a XML \u89e3\u6790\u9032\u884c\u9078\u9805\u8a2d\u7f6e<br \/>\n\t\txml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);<br \/>\n\t\t\/\/xml_parse_into_struct &#8212; \u5c07 XML \u6578\u64da\u89e3\u6790\u5230\u6578\u7d44$values\u4e2d<br \/>\n\t\txml_parse_into_struct($parser, $buff, $values, $idx);<br \/>\n\t\t\/\/xml_parser_free &#8212; \u91cb\u653e\u6307\u5b9a\u7684 XML \u89e3\u6790\u5668<br \/>\n\t\txml_parser_free($parser);<br \/>\n\t\tforeach ($values as $val) {<br \/>\n\t\t\t$tag = $val[&quot;tag&quot;];<br \/>\n\t\t\t$type = $val[&quot;type&quot;];<br \/>\n\t\t\t$value = $val[&quot;value&quot;];<br \/>\n\t\t\t\/\/\u6a19\u7c64\u7d71\u4e00\u8f49\u70ba\u5c0f\u5beb<br \/>\n\t\t\t$tag = strtolower($tag);<br \/>\n\t\t\tif ($tag == &quot;item&quot; &amp;&amp; $type == &quot;open&quot;) {<br \/>\n\t\t\t\t$is_item = 1;<br \/>\n\t\t\t} else if ($tag == &quot;item&quot; &amp;&amp; $type == &quot;close&quot;) {<br \/>\n\t\t\t\/\/\u69cb\u9020\u8f38\u51fa\u5b57\u7b26\u4e32<br \/>\n\t\t\t\t$is_item = 0;<br \/>\n\t\t\t\t$finish.=$title.&#8217;&amp;nbsp;&#8217;;\/\/\u5c07\u7d50\u679c\u4e32\u63a5\u8d77\u4f86 \u4ee5 &amp;nbsp; \u505a\u5206\u5272<br \/>\n\t\t\t}<br \/>\n\t\t\t\/\/\u50c5\u8b80\u53d6item\u6a19\u7c64\u4e2d\u7684\u5167\u5bb9<br \/>\n\t\t\tif ($is_item == 1) {<br \/>\n\t\t\t\tif ($tag == &quot;title&quot;) {<br \/>\n\t\t\t\t\t$title = $value;<br \/>\n\t\t\t\t}<br \/>\n\t\t\t\tif ($tag == &quot;link&quot;) {<br \/>\n\t\t\t\t\t$link = $value;<br \/>\n\t\t\t\t}<br \/>\n\t\t\t}<br \/>\n\t\t}<br \/>\n\t}<br \/>\n\t$output=array();<br \/>\n\t$output = explode(&quot;&amp;nbsp;&quot;, $finish);\/\/\u4f9d &amp;nbsp; \u4f86\u5206\u5272\u5b57\u4e32 \u5c07\u5206\u5272\u7d50\u679c\u5b58\u5165\u9663\u5217<br \/>\n\tarray_pop($output);\/\/\u79fb\u9664\u6700\u5f8c\u4e00\u500b\u9663\u5217\u5143\u7d20<br \/>\n\tprint_r($output);\/\/\u986f\u793a\u9663\u5217<br \/>\n?&gt;<br \/>\n[\/php]<br \/>\n\u986f\u793a\u7d50\u679c\uff1a<br \/>\nArray ( [0] => \u6642\u4ee3\u79fb\u8f49\uff0c\u53f0\u7063\u9ea5\u7576\u52de\u8d70\u5411\u4e0b\u4e00\u500b\u6642\u4ee3 [1] => \u9435\u78b3\u4f01\u696d\u6210\u70ba\u53f0\u7063\u54c1\u724c\u65b0\u5c16\u5175 [2] => \u56b4\u51f1\u6cf0\u5f97\u5b50\u597d\u5fc3\u60c5\u85cf\u4e0d\u4f4f\u3000\u5c08\u696d\u80a1\u6771\u63d0\u554f\u6709\u554f\u5fc5\u7b54 [3] => \u5168\u7403\u52de\u52d5\u4eba\u53e3\u6301\u7e8c\u7e2e\u6e1b\uff0c\u667a\u6167\u578b\u6a5f\u5668\u4eba\u5e02\u5834\u9700\u6c42\u5c07\u5feb\u901f\u6210\u9577 [4] => \u5168\u7403\u52de\u52d5\u4eba\u53e3\u6301\u7e8c\u7e2e\u6e1b\uff0c\u667a\u6167\u578b\u6a5f\u5668\u4eba\u5e02\u5834\u9700\u6c42\u5c07\u5feb\u901f\u6210\u9577 [5] => \u5bc4\u51fa\u7684email\u3000\u4e0d\u518d\u662f\u8986\u6c34\u96e3\u6536 [6] => \u53f2\u4e39\u4f5b\u5927\u5b78\u9a5a\u4eba\u7814\u7a76\uff0c\u5730\u7403\u53f2\u4e0a\u7b2c\u516d\u6b21\u7269\u7a2e\u6ec5\u7d55\u5df2\u6572\u97ff\u9418 [7] => \u9678\u80a1\u8df3\u6c34\u3000\u662f\u5d29\u76e4\u9084\u662f\u4fee\u6b63\uff1f [8] => \u5beb\u4e0b\u53f0\u7063\u6c11\u5bbf\u7684\u5922\u60f3\u3000\u50b3\u905e\u611f\u52d5 [9] => \u300c\u63db\u65e5\u7dda\u300d\u6d77\u5916\u9752\u5e74\u6709\u8a71\u8981\u8aaa [10] => \u62ef\u6551\u54e1\u5de5\u4eba\u751f\u3000\u6bd4\u6578\u9214\u7968\u66f4\u5e78\u798f [11] => \u4e00\u767e\u500b\u9a5a\u559c\u66f8\u888b\u3000\u7368\u7acb\u66f8\u5e97\u5275\u5b8c\u552e\u5947\u8e5f [12] => \u97d3\u5bb6\u5bf0x\u59da\u91cf\u8b70\uff1a\u5c0f\u8fb2\u751f\u547d\u529b\u3000\u4f60\u8a72\u53bb\u6cd5\u570b\u770b\u770b(2) [13] => Apple Music\u8a66\u807d\u4e0d\u4ed8\u7248\u7a05\u3000\u5c0f\u5929\u540e\u6230\u52dd\u5927\u860b\u679c [14] => \u8edf\u9280Pepper\u4e00\u5206\u9418\u79d2\u6bba\u3000\u8207\u6a5f\u5668\u4eba\u640f\u611f\u60c5\u7684\u6642\u4ee3\u4f86\u4e86 [15] => \u908a\u8d70\u8def\u908a\u6ed1\u624b\u6a5f\u3000\u8a2d\u5c08\u7528\u4eba\u884c\u9053\u662f\u597d\u4e3b\u610f\uff1f [16] => \u7a7a\u62cd\u6a5f\u767c\u71d2\u3000\u5929\u7a7a\u5546\u6a5f\u958b\u6230 [17] => \u9109\u6c11\u7684\u300c\u5275\u4e16\u795e\u300d \u6311\u6230\u79d1\u6280\u7121\u6975\u9650 [18] => \u300c\u7d05\u91d1\u300d\u756a\u7d05\u82b1\u3000\u70ba\u4ec0\u9ebc\u6bd4\u9ec3\u91d1\u9084\u8cb4\uff1f [19] => \u597d\u559d\u5496\u5561\u80cc\u5f8c\uff1a\u7adf\u662f\u7f8e\u9e97\u611b\u60c5\uff1b\u58de\u6d88\u606f\u662f\uff1a\u5b83\u5feb\u7d55\u7a2e\u4e86 )\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[php] &lt;?php $rss=&#038;quot&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[491],"class_list":["post-173","post","type-post","status-publish","format-standard","hentry","category-php","tag-rss"],"_links":{"self":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=173"}],"version-history":[{"count":0,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/173\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}