Home  >  Article  >  Backend Development  >  Getting Started with XML Manipulation via PHP_PHP Tutorial

Getting Started with XML Manipulation via PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:37:45811browse


PHP PEAR provides an RSS parsing class to facilitate obtaining corresponding information from the RSS provided by users.
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 specific paths can be debugged a little. After decompressing the compressed package, I put the RSS.php, Parser.php and PEAR.php inside in the same directory, and then put the
require_once XML/Parser.php;
Change to
require_once XML/Parser.php;
It's ready to use.

RSS version
After a simple test, I found that it works very well for the above three major versions of RSS without any problems. Indicates that it supports at least the major versions of RSS (0.91, 1.0, 2.0)

Example
Using XML_RSS to parse RSS is particularly simple. Include the class file first:
require "RSS.php";

Create a class instance based on the resource address:
$url = "test.rss";
$r =& new XML_RSS($url);

Of course, $url here can also be a remote path. This requires setting allow_url_fopen in php.ini to On, because it is set to this by default, so it generally does not need to be changed.

Perform analysis:
$r->parse();

You can get various information below:
$r->getStructure() returns an array containing all structure information of the RSS file.
$r->getChannelInfo() returns an array containing summary information of the current RSS channel, such as title, link, description, etc.
$r->getItems() returns a two-dimensional array that contains all item information in the RSS file. Each set of information includes title, link, description, date, etc.
$r->getImages() returns a two-dimensional array that contains all image information in the RSS file. Each set of information includes title, link, url, etc.
$r->getTextinputs() returns a two-group array that contains all file input area information in the RSS file. Each group of information includes title, link, description, name, etc.

How to print a content list 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 link; title: content title; description: content description; pubdate: content publication date, which depends on the site and may not be provided
?>
" target="_blank">
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486541.htmlTechArticlePHP PEAR provides an RSS parsing class to facilitate obtaining corresponding information from the RSS provided by users. Requirements Download XML_RSS: http://pear.php.net/package/XML_RSS XML_Parser http://pear.php...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn