PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » XML » XML_RSS » Manual

Parser for Resource Description Framework (RDF) Site Summary (RSS) documents.

Introduction

Introduction – Introduction to XML_RSS

Introduction to XML_RSS

Resource Description Framework (RDF) Site Summary (RSS) documents are XML documents, that provide a lightweight multipurpose extensible metadata description and syndication format. RSS files are often used to syndicate news or headlines from portal sites (e.g. Slashdot or freshmeat.net) or weblogs.

For more information on RSS see the website of the RSS working group (http://tech.groups.yahoo.com/group/rss-dev/files/specification.html).

RSS file

<?xml version="1.0"?>

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns="http://my.netscape.com/rdf/simple/0.9/">

<channel>
 <title>FooBar Inc.</title>
 <link>http://example.com/</link>
 <description>abcd, xyz, 123</description>
</channel>

<image>
 <title>FooBar</title>
 <url>http://example.com/images/rssicon.gif</url>
 <link>http://example.com/</link>
</image>

<item>
 <title>Headline 1</title>
 <link>http://example.com/news.php?h=1</link>
</item>

<item>
 <title>Headline 2</title>
 <link>http://example.com/news.php?h=2</link>
</item>

<textinput>
 <title>Search FooBar Inc.</title>
 <description>Search FooBar Inc. headlines</description>
 <name>q</name>
 <link>http://example.com/search.php</link>
</textinput>

</rdf:RDF>

Requirements

Requirements – Requirements for running XML_RSS

XML_Parser

To parse the XML files that contain the RSS feeds, XML_RSS requires that the package XML_Parser is installed. However this dependency will be automatically handled by the installer during the installation phase of XML_RSS.

allow_url_fopen configuration value

Since most RSS feeds are located on remote hosts, one has to ensure that the PHP configuration value "allow_url_fopen" is set to "On" before running XML_RSS.

To find out the current value of "allow_url_fopen", one can use the function ini_get(). To set a new value of "allow_url_fopen", you must modify the php.ini configuration file of PHP.

Example

Example – Example for the usage of XML_RSS

Usage example

The following script fetches the latest headlines from Slashdot.org via RSS.

Fetching headlines from Slashdot

<?php
require_once "XML/RSS.php";

$rss =& new XML_RSS("http://rss.slashdot.org/Slashdot/slashdot");
$rss->parse();

echo "<h1>Headlines from <a href=\"http://slashdot.org\">Slashdot</a></h1>\n";
echo "<ul>\n";

foreach ($rss->getItems() as $item) {
    echo "<li><a href=\"" . $item['link'] . "\">" . $item['title'] . "</a></li>\n";
}

echo "</ul>\n";
?>

XML_RSS::XML_RSS

XML_RSS::XML_RSS – Constructor

Synopsis

require_once "XML/RSS.php";

void XML_RSS::XML_RSS ( mixed $handle='' )

Description

Constructor

Parameter

Note

This function can not be called statically.

Example

Using XML_RSS()

<?php
$r =& new XML_RSS("test.rss");
?>

XML_RSS::getStructure

XML_RSS::getStructure – Get complete structure of RSS file

Synopsis

require_once "XML/RSS.php";

array XML_RSS::getStructure ( )

Description

Get complete structure of RSS file

Return value

array - the array depends on the structure of the RSS document.

Note

This function can not be called statically.

XML_RSS::getChannelInfo

XML_RSS::getChannelInfo – Get general information about current channel

Synopsis

require_once "XML/RSS.php";

array XML_RSS::getChannelInfo ( )

Description

Get general information about current channel. This function returns an array containing the information that has been extracted from the <channel>-tag while parsing the RSS document.

Return value

array - an array of strings. The keys of the array are

Note

This function can not be called statically.

XML_RSS::getItems

XML_RSS::getItems – Get items from RSS file

Synopsis

require_once "XML/RSS.php";

array XML_RSS::getItems ( )

Description

Get items from RSS document. This function returns an array containing the set of items that are provided by the RSS document.

Return value

array - a two-dimensional array. Every inner array contains information about a site. Use the array key 'title' to get the article title and the key 'link' for the URL of the site.

Note

This function can not be called statically.

Example

Using getItems()

<?php
foreach ($r->getItems() as $value) {
    echo $value['title'] . ": " . $value['link'] . "\n";
}
?>

XML_RSS::getImages

XML_RSS::getImages – Get images from RSS document

Synopsis

require_once "XML/RSS.php";

array XML_RSS::getImages ( )

Description

Get images from RSS document. This function returns an array containing the set of images that are provided by the RSS document.

Return value

array - a two-dimensional array. Every inner array contains information about an image of a site.

Note

This function can not be called statically.

XML_RSS::getTextinputs

XML_RSS::getTextinputs – Get text input fields from RSS document

Synopsis

require_once "XML/RSS.php";

array XML_RSS::getTextinputs ( )

Description

Get text input fields from RSS document.

Return value

array - an hash containing the data of an input field

Note

This function can not be called statically.