PHP Pear provides an RSS parsing class that makes it easy to get the appropriate information from the user-provided RSS.
Demand
Download Xml_rss:http://pear.php.net/package/xml_rss
Xml_parser Http://pear.php.net/package/XML_Parser
PEAR Http://pear.php.net/package/PEAR
The relationship between the specific paths, a little debugging can be, I am the compression package decompression, the inside of the rss.php,parser.php,pear.php are placed in the same directory, and then the rss.php inside the
Require_once xml/parser.php;
Change into
Require_once xml/parser.php;
You can use it.
RSS version
After a simple test, I found that it worked well for the three major versions of RSS above and did not have any problems. Stating that it is at least supported for RSS major versions (0.91,1.0,2.0)
Example
Using Xml_rss to analyze RSS is particularly straightforward. Include the class file first:
Require "rss.php";
To create a class instance from a resource address:
$url = "Test.rss";
$r =& New Xml_rss ($url);
Of course, the php.ini here can also be a remote path, which needs to set the Allow_url_fopen to ON, because it is the default setting is for this, so generally do not change.
Perform analysis:
$r->parse ();
Here are a variety of information:
$r->getstructure () return is an array that contains all the structure information for the RSS file.
$r->getchannelinfo () return is an array that contains summary information about the current channel of the RSS, such as Title,link,description.
$r->getitems () returns a two-dimensional array that contains all the item information in the RSS file, title,link,description,date in each set of information, and so on.
$r->getimages () returns a two-dimensional array containing all the image information in the RSS file, with Title,link,url in each set of information.
$r->gettextinputs () returns a two-group array containing all the file input area information in the RSS file, with Title,link,description,name in each set of information.
How to print a list of content based on an address
$url = "Http://www.BkJia.com/data/rss/37.xml";
$r =& New Xml_rss ($url);
$r->parse ();
$items = $r->getitems ()
foreach ($items as $k = $item)
{
$item contains link: content links; title: content title; Description: Content description; pubdate: Content table cloth date, depending on site, not necessarily provide
?>
"target=" > "_blank"
}
?>
http://www.bkjia.com/PHPjc/486541.html www.bkjia.com true http://www.bkjia.com/PHPjc/486541.html techarticle PHP Pear provides an RSS parsing class that makes it easy to get the appropriate information from the user-provided RSS. Request Download Xml_rss:http://pear.php.net/package/xml_rss Xml_parser http://pear.php ...