Recently in the blog, but a variety of blog synchronization between the trouble, fortunately, each blog has its own RSS aggregation system, can be implemented through RSS blog call, so that their own hands-on RSS blog to achieve synchronization, in which to study PHP read RSS.
RSS is written in XML, and XML is a data storage format. PHP has three ways to read XML data: XML parsing functions, DOM modules, and regular expressions, most directly parsing XML directly to get the data in the XML.
The following is the parsing code:
Copy the Code code as follows:
Error_reporting (E_all^e_notice);
$rssfeed = "Feed.xml";
Header (' content-type:text/html;charset= UTF-8 ');
$buff = "";
Open the RSS address and read
$fp = fopen ($rssfeed, "R") or Die ("Can not open $rssfeed");
while (!feof ($fp)) {
$buff. = Fgets ($fp, 4096);
}
Close File
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
echo "". $title. "
";
echo $content. "
";
$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;}
if ($tag = = "content:encoded") {$content = $value;}
}
}
?>
The following is the effect of reading the feed with this program:
http://www.bkjia.com/PHPjc/788627.html www.bkjia.com true http://www.bkjia.com/PHPjc/788627.html techarticle recently in the blog, but a variety of blog synchronization between the trouble, fortunately, each blog has its own RSS aggregation system, can be implemented through RSS blog call, so I do the RSS real ...