This is where the RSS reading Function Program On the basis
If an array string is output and the encoding problem is solved.
PHPSource codeAndCodeThe detailed explanation is as follows:
<? PHP
// RSS source 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 the encoding to UTF-8
Header ('content-type: text/html; charset = UTF-8 ');
For ($ I = 0; $ I <sizeof ($ rssfeed); $ I ++) {// start of Decomposition
$ Buff = "";
$ Rss_str = "";
// Open the RSS address and read it. If reading fails, stop
$ Fp = fopen ($ rssfeed [$ I], "R") or die ("can not open $ rssfeed ");
While (! Feof ($ FP )){
$ Buff. = fgets ($ FP, 4096 );
}
// Close the file
Fclose ($ FP );
// Create an XML Parser
$ Parser = xml_parser_create ();
// Xml_parser_set_option -- set options for specified XML Parsing
Xml_parser_set_option ($ parser, xml_option_skip_white, 1 );
// Xml_parse_pai_struct -- Parse XML data to the array $ values
Xml_parse_into_struct ($ parser, $ buff, $ values, $ idx );
// Xml_parser_free -- release the specified XML Parser
Xml_parser_free ($ parser );
Foreach ($ values as $ Val ){
$ Tag = $ Val ["tag"];
$ Type = $ Val ["type"];
$ Value = $ Val ["value"];
// Convert tags to lowercase
$ Tag = strtolower ($ tag );
if ($ tag = "item" & $ type = "open") {
$ is_item = 1;
} else if ($ tag = "item" & $ type = "close") {
// construct the output string
$ rss_str. = " ". $ title. "
";
$ is_item = 0;
}< br> // read only the content in the item tag
if ($ is_item = 1) {
if ($ tag = "title ") {$ Title = $ value ;}< br> if ($ tag = "Link") {$ link = $ value ;}
}< BR >}< br> // output result
echo $ R Ss_str. "
";
}< BR >?>