Because the site needs to read different sources of RSS feed, write a PHP program to read the RSS feed, in order to facilitate reading and understand the process of implementation, plus comments, and we learn together. and help Easy Net RSS reading is in this program based on a slightly modified, mainly output an array string and solve the coding problem.
The PHP source code and code are explained in detail as follows:
<?php //rss Source Address List array $rssfeed = Array ("Http://www.jzxue.com/rss/12.xml", http://rss.sina.com.cn /news/allnews/sports.xml ", " Http://ent.163.com/special/00031K7Q/rss_toutiao.xml ", " http:// Tech.163.com/special/00091jpq/techimportant.xml "); //Set encoded as utf-8 header (' content-type:text/html;charset= UTF-8 '); for ($i =0; $i < sizeof ($rssfeed); $i + +) {//decomposition start $buff = "" "; $rss _str=" "; //Open RSS address and read, read failed abort $fp = fopen ($rssfeed [$i], "R") or Die ("Can not open $rssfeed"); while (!feof ($fp)) { $buff. = Fgets ($fp, 4096); } // Close File Open fclose ($fp); //Create an XML parser $parser = xml_parser_create (); //xml_parser_set_option--option settings for specified XML parsing xml_parser_set_ Option ($parser, xml_option_skip_white,1); //xml_parse_into_struct-parsing XML data to an array $ Values xml_parse_into_struct ($parser, $buff, $values, $idx); //xml_parser_free--frees the specified XML parser xml_parser_free ($parser); foreach ($values as $val) { $tag = $val ["tag"]; $type = $val [" Type ']; $value = $val [' Value ']; //label unification to lowercase $tag = strToLower ($tag); if ($tag = = "Item" && $type = = "Open") { $is _item = 1; }else if ($tag = = " Item "&& $type = =" Close ") { / /construct output string $rss _str. = "<a href=". $link. "' Target=_blank>". $title. " </a><br/> "; $is _item = 0; } /Read Only the contents of the item label if ($is _item==1) { if ($tag = = "title") {$title = $value;} if ($tag = = "link") {$link = $value;} } } //Output echo $rss _str. " <br/> "; } ?>