Home arrow MySQL arrow Page 3 - Creating an RSS Reader: the Reader

The Meat of the Code - MySQL

In this article we are going to discuss how to create a PHP-based RSS reader. It would be helpful if you know something about XML, but not really necessary. RSS documents have three main tags: Title, Link and Description. And they all do exactly what their names suggest. I will go into detail about these tags in my second article dealing with “building an RSS file.” For now, we will only focus on the “reading” part of the article.

TABLE OF CONTENTS:
  1. Creating an RSS Reader: the Reader
  2. XML-related Functions
  3. The Meat of the Code
  4. Reading RSS Data from a Database (Optional)
By: Jacques Noah
Rating: starstarstarstarstar / 16
February 06, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Now that we have created the required functions, let's continue with the meat of the code:

function parsefile($RSSfile){

  // Create an xml parser

  $xmlParser = xml_parser_create();

  // Set up element handler

  xml_set_element_handler( $xmlParser, "startTag", "endTag" );

  

  // Set up character handler

  xml_set_character_data_handler( $xmlParser, "TxtTag" );

  // Open connection to RSS XML file for parsing.

  $fp = fopen( $RSSfile,"r" )

    or die( "Cannot read RSS data file." );

   

  // Parse XML data from RSS file.

  while( $data = fread( $fp, 4096 ) ) {

    xml_parse( $xmlParser, $data, feof( $fp ) );

or die(sprintf("XML error: %s at line %d",  
           xml_error_string(xml_get_error_code($xml_parser)),  
           xml_get_current_line_number($xml_parser)));

  }

  

  // Close file open handler

  fclose( $fp );

  // Free xml parser from memory

  xml_parser_free( $xmlParser );

  }

The above function calls both the startTag/endTag functions to loop through the XML file and displays the contents.



 
 
>>> More MySQL Articles          >>> More By Jacques Noah
 

blog comments powered by Disqus
   

MYSQL ARTICLES

- Xeround Releases Free Version of MySQL Cloud...
- Oracle Announces New MySQL Specialization
- Constant Contact Chooses SkySQL for MySQL Su...
- Revoke Statement in MySQL
- The Grant Statement in MySQL
- SuccessBricks Announces ClearDB Availability...
- Building a PHP ORM: Deploying a Blog
- TROSYS Launches Free MySQL Manager and Admin...
- Building an ORM in PHP: Domain Modeling
- Building an ORM in PHP
- MySQL Leads Open Source Market, Gets Cluster...
- Oracle Announces Milestone Release for MySQL
- How to Stop SQL Injection Attacks
- New Defragmentation Solution for SQL Server
- Comparison of MyISAM and InnoDB MySQL Databa...


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap

Dev Shed Tutorial Topics: