and the RSS feed of the Help net is on the basis of this program to do a little transformation, the main
If an array string is output and the encoding problem is resolved.
The PHP source code and code are explained in detail as follows:
RSS Feed Address List Array
$rssfeed = Array ("Http://www.jb51.net/feed",
"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 Encoding to UTF-8
Header (' content-type:text/html;charset= UTF-8 ');
for ($i =0; $i $buff = "";
$rss _str= "";
Open RSS address and read, read failed to abort
$fp = fopen ($rssfeed [$i], "R") or Die ("Can is 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 setting for specifying XML parsing
Xml_parser_set_option ($parser, xml_option_skip_white,1);
Xml_parse_into_struct--parsing XML data into array $values
Xml_parse_into_struct ($parser, $buff, $values, $IDX);
Xml_parser_free--Releases 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") {
Constructing the output string
$rss _str. = "". $title. "
";
$is _item = 0;
}
Read only the contents of the item tag
if ($is _item==1) {
if ($tag = = "title") {$title = $value;}
if ($tag = = "link") {$link = $value;}
}
}
Output results
echo $rss _str. "
";
}
?>
http://www.bkjia.com/PHPjc/319327.html www.bkjia.com true http://www.bkjia.com/PHPjc/319327.html techarticle The RSS reading of the Help Net is a minor modification on the basis of this program, which mainly outputs an array string and solves the coding problem. PHP source code and code explained in detail as follows ...