WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - השוואת מחירים בסופר
ZeroLag.com
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : RSS parser. Parses RSS into an array. Quick and nasty but does the job. No checking is done for correct Tags, only correct XML. PHP4 needed to display result (uses print_r).
Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS) Update Picture
Herman Veluwenkamp
Date : Jun 07th 2000
Grade : 2 of 5 (graded 7 times)
Viewed : 16307
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Herman Veluwenkamp
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?
header('content-type: text/plain');

// define hooks to rss_parser class as xml functions do not allow object methods as handlers.
function rss_start_element($parser, $name, $attributes) {
global $rss;
$rss->start_element($parser, $name, $attributes);
}

function rss_end_element($parser, $name) {
global $rss;
$rss->end_element($parser, $name);
}

function rss_character_data($parser, $data) {
global $rss;
$rss->character_data($parser, $data);
}


class rss_parser {

// constructor. setup parser options and handlers.
function rss_parser() {
$this->error = '';
$this->file = '';

$this->channel = array();
$this->data = '';
$this->stack = array();
$this->num_items = 0;

$this->xml_parser = xml_parser_create();
xml_set_element_handler($this->xml_parser, "rss_start_element", "rss_end_element");
xml_set_character_data_handler($this->xml_parser, "rss_character_data");
}

function character_data($parser, $data) {
if (empty($this->data)) $this->data = trim($data); // concatenate non-parsed data...
else $this->data .= ' '.trim($data); // and get rid of white space.
}

function start_element($parser, $name, $attrs) {
switch($name) {
case 'RSS':
break;

case 'CHANNEL':
break;

case 'IMAGE':
array_push($this->stack, $name);
break;

case 'ITEM':
array_push($this->stack, $name);
array_push($this->stack, $this->num_items); // push item index.
$this->item[$this->num_items] = array();
$this->num_items++;
break;

case 'TEXTINPUT':
array_push($this->stack, $name);
break;

default:
array_push($this->stack, $name);
break;

}
}

function end_element($parser, $name) {
switch ($name) {
case 'RSS':
break;

case 'CHANNEL':
break;

case 'IMAGE':
array_pop($this->stack);
break;

case 'ITEM':
array_pop($this->stack);
array_pop($this->stack);
break;

case 'TEXTINPUT':
array_pop($this->stack);
break;

default: // child element.
$element = (implode("']['",$this->stack));
eval("\$this->channel['$element']=\$this->data;"); // this does all the hard work.
array_pop($this->stack);
$this->data = '';
break;
}
}


function parse() {
if (!($fp = @fopen($this->file, "r"))) {
$this->error = "Could not open RSS source \"$this->file\".";
return false;
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($this->xml_parser, $data, feof($fp))) {
$this->error = sprintf("XML error: %s at line %d.",
xml_error_string(xml_get_error_code($this->xml_parser)),
xml_get_current_line_number($this->xml_parser));
return false;
}
}
xml_parser_free($this->xml_parser);
return true;
}




} // class rss_parser.

// try it out...
$rss = new rss_parser();
$rss->file = 'http://freebsddiary.org/news.php3';
$rss->parse() or die($rss->error);
if ($rss->error) print $rss->error;

print_r($rss->channel); // PHP 4 needed for this to work.
?>



XML easy parser
Categories : PHP, XML, PHP Classes
Directory Listing To XML : Outputs XML File of a Given Directory Listing
Categories : PHP, PHP Classes, XML, Directories
XPath for PHP without the DOM XML extension
Categories : DOM XML, XML, XSLT, PHP Classes, PHP
[PHP5] PHP Debugger and Helper
Categories : PHP, PHP Classes, Errors and Logging, Debugging, XML
AutoRSS
Categories : PHP, Rich Site Summary (RSS), PHP Classes
Simple newsreader script
Categories : PHP, XML, Rich Site Summary (RSS)
Freshmeat.net XML-RPC - This class is meant to query Freshmeat for information about registered projects.
Categories : PHP, PHP Classes, XML, Web Services
XML To Array
Categories : PHP, PHP Classes, XML, Arrays
Football News Aggregator
Categories : PHP, Object Oriented, PHP Classes, Rich Site Summary (RSS), HTML and PHP
RSS parser using PHP5 and simpleXML
Categories : Rich Site Summary (RSS), PHP, XML
DBXML- A Class to backup databases in XML Format using web interface
Categories : PHP, PHP Classes, Databases, MySQL, XML
XML Menu
Categories : PHP, PHP Classes, Navigation, XML, XSL
A very basic and fast XML parser
Categories : PHP, PHP Classes, XML
TAB_STRUCT Class: Is supporting Class for the DBXML Class
Categories : PHP, PHP Classes, MySQL, XML, Databases
logger class (PHP5 +)
Categories : PHP, PHP Classes, Log Files, XML