Comunitatea PHP Romania
 

 
Introduction and Quick Start

Introduction and Quick Start

Introduction and Quick Start -- Overview of XML_Feed_Parser

Description

XML_Feed_Parser provides a generic interface to a number of the most popular XML-based syndication formats (Atom, RSS1, RSS2, etc). In order to focus on its core competencies, it does not provide any HTTP or feed creation features, but instead parses a wide range of formats quickly and simply.

Presuming the XML for a feed is stored in the variable $xml_source, the simplest way to create an instance of the parser is:

try {
    $feed = new XML_Feed_Parser($xml_source);
} catch (XML_Feed_Parser_Exception $e) {
    die('Feed invalid: ' . $e->getMessage());
}

The constructor accepts a number of parameters, as follows:

/* The file you wish to parse */
$source = 'my_source.xml';

/* Where Relax NG is available, we can force validation of the feed */
$validate = true;

/* Whether or not to suppress non-fatal warnings */
$suppress_warnings = false;

/* If the feed is not valid XML and the tidy extension is installed we can
 * attempt to use it to fix the feed */
$use_tidy = true;

$feed = new XML_Feed_Parser($source, $validate, $suppress_warnings, $use_tidy);

Once you have an instance of the parser you can extract feed-level data by querying it directly. eg.

$title = $feed->title;

You can also access elements by iterating over the feed, or directly by offset or id.

foreach ($feed as $entry) {
    print $entry->title . "\n";
}

$first_entry = $feed->getEntryByOffset(0);

$particular_entry = $feed->getEntryById('http://jystewart.net/entry/1');

Ultimele discutii in forum RSS Forum

Ultimele articole Ultimele articole

Top membri

Pirahna Pirahna
la birou
carco carco
Bucuresti
Birkoff Birkoff
Bucuresti
mihaitha mihaitha
Sibiu
Mascka Mascka
Braila
gabysolomon gabysolomon
Bacau
whooper whooper
Toronto ON
raul_ raul_
dechim dechim
Drobeta Turnu Severin
Amenthes Amenthes

Newsletter


Email:
 inscriere
 renuntare
 
 Arhiva newsletter

Parteneriat

Copyright © 2001-2008 PHP Romania Add PHPRomania to Google Add PHPRomania to Del.icio.us Add PHPRomania to Stumbleupon Add PHPRomania to Yahoo! Add PHPRomania to Digg Add PHPRomania to Blink Car Credit | Gas Suppliers | Loans | Loan | Loans
Ads: Partener Way2Web Nework: gazduire web | inregistrare domenii | web design | imobiliare | web hosting
Powered by Simplis