从 google URL 中提取站点 link

Extract site link from google URL

我想从 Google URL 中提取站点 link,我需要一种有效的方法来执行此操作, 我已经提取了这个,但我对此感到不舒服,

$googleURL = "http://www.google.ca/local_url?dq=food+Toronto,+ON&q=https://plus.google.com/110334461338830338847/about%3Fgl%3DCA%26hl%3Den-CA&ved=0CHAQlQU&sa=X&ei=HzrCVNX-JqSzigb-94D4CQ&s=ANYYN7nQx_FiR1PuowDmXBi1oyfkI2MImg";

我想要这个

https://plus.google.com/110334461338830338847/

我是按照以下方式完成的。

$first = current(explode("about", $googleURL)); // returns http://www.google.ca/local_url?dq=food+Toronto,+ON&q=https://plus.google.com/110334461338830338847/

然后,

$myLink = explode("&q=", $first);
echo $myLink[1]; // return my need => https://plus.google.com/110334461338830338847/

但 googleURL 中可能有两个 "about" 或“&q=”,这可能会导致问题。

我知道,这个 googleURL 将被重定向到我的需要,但我需要那个特定的 link 是有目的的。

我想解析它并不安全,因为 google 可以随时更改其实现。

但是,如果您想从字符串中获取参数 url,这个问题很好地涵盖了它:

How to get parameters from a URL string?

$parts = parse_url($googleUrl);
parse_str($parts['query'], $query);
echo $query['q'];