Results 1 to 2 of 2

Thread: RSS Parser

  1. #1
    Andy101's Avatar
    Andy101 is offline Code Otaku
    Join Date
    Aug 2009
    Location
    Japan/uk
    Posts
    699
    Thanks
    100
    Thanked 217 Times in 161 Posts

    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;

    Article authors check out: Resource Box Wizard

  2. Thanked by:

    m42 (12 October, 2010), Will.Spencer (9 October, 2010)

  3. #2
    Andy101's Avatar
    Andy101 is offline Code Otaku
    Join Date
    Aug 2009
    Location
    Japan/uk
    Posts
    699
    Thanks
    100
    Thanked 217 Times in 161 Posts
    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); 
    Article authors check out: Resource Box Wizard

  4. Thanked by:

    m42 (12 October, 2010)

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, 00: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
  •