doujiu3882 2012-01-15 14:46
浏览 62
已采纳

通过PHP从Google新闻RSS获取实际链接

I want to parse Google News RSS with PHP, to get actual links of the content.

Google News RSS item link looks like this:

http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNGkF58EwDE7aA742GfVP9aE8azmhg&url=http://www.reuters.com/article/2012/01/15/us-obama-mlk-idUSTRE80E0PD20120115

I need just the actual link, everything after &url= :

http://www.reuters.com/article/2012/01/15/us-obama-mlk-idUSTRE80E0PD20120115

And how would one go about eliminating the "non-essential" part of the URL, in essence targeting everything starting with http://news.google.com and ending with &url= ?

http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNGkF58EwDE7aA742GfVP9aE8azmhg&url=

I do a little regex, but this is out of my reach...

Thanks, fellas!

  • 写回答

2条回答 默认 最新

  • dqunzip3183 2012-01-15 15:05
    关注

    Regex is not necessarily the best approach here.

    $query = parse_url($google_url, PHP_URL_QUERY);
    parse_str($query, $parts);
    $url = $parts['url'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部