Parsing Google News RSS with PHP

后端 未结 3 793
逝去的感伤
逝去的感伤 2020-12-16 07:56

I want to parse Google News rss with PHP. I managed to run this code:



        
3条回答
  •  南方客
    南方客 (楼主)
    2020-12-16 08:12

    There we go, just what you need for your particular situation:

    channel->item as $item) 
    {
        preg_match('@src="([^"]+)"@', $item->description, $match);
        $parts = explode('', $item->description);
    
        $feeds[$i]['title'] = (string) $item->title;
        $feeds[$i]['link'] = (string) $item->link;
        $feeds[$i]['image'] = $match[1];
        $feeds[$i]['site_title'] = strip_tags($parts[1]);
        $feeds[$i]['story'] = strip_tags($parts[2]);
    
        $i++;
    }
    
    echo '
    ';
    print_r($feeds);
    echo '
    '; ?>

    And the output should look like this:

    [2] => Array
            (
                [title] => Los Alamos Nuclear Lab Under Siege From Wildfire - ABC News
                [link] => http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNGxBe4YsZArH0kSwEjq_zDm_h-N4A&url=http://abcnews.go.com/Technology/wireStory?id%3D13951623
                [image] => http://nt2.ggpht.com/news/tbn/OhH43xORRwiW1M/6.jpg
                [site_title] => ABC News
                [story] => A wildfire burning near the desert birthplace of the atomic bomb advanced on the Los Alamos laboratory and thousands of outdoor drums of plutonium-contaminated waste Tuesday as authorities stepped up ...
            )
    

提交回复
热议问题