Results 1 to 2 of 2

Thread: RSS Parser

Hybrid View

  1. #1

    RSS Parser

    This is an easy way to convert RSS data to an array so that it is easy to access that data and do stuff with it, enjoy:

    PHP Code:
    function parse_rss($data) {
        
    $data iconv('UTF-8''UTF-8//IGNORE'$data); // Remove invalid characters
        
        
    $xml_parser xml_parser_create();
        
    xml_parser_set_option($xml_parserXML_OPTION_TARGET_ENCODING'UTF-8'); 

        if (!
    xml_parse_into_struct($xml_parser$data$vals$index)) {
            die(
    sprintf("XML error: %s at line %d",
                
    xml_error_string(xml_get_error_code($xml_parser)),
                
    xml_get_current_line_number($xml_parser)));
        }
        
    xml_parser_free($xml_parser);
        
        return 
    $vals;


  2. #2
    To experiment with the above code you could try:

    <pre>
    PHP Code:
    $data file_get_contents("http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&q=weight+loss&cf=all&output=rss");

    $result parse_rss($data);

    print_r($result); 

Similar Threads

  1. ZB Block 0.4.5 (PHP Security Pre-Parser) Released
    By zaphod in forum Programming
    Replies: 1
    Last Post: 23 November, 2009, 01:20 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •