开发者

regex to get $_GET variables

I have a URL string and would like to extract parts of the URL. I have been trying to do understand how to do it with regex but no luck.

http://www.example.com?id=example.id&v=other.variable

From the example above I would li开发者_JAVA技巧ke to extract the id value ie. example.id


I'm assuming you're not referring to actual $_GET variables, but to a string containing a URL with a query string.

PHP has built-in functions to process those:

  • parse_url() to extract the query string from a URL
  • parse_str() to split the query string into its components


No need for regexp here, just use php built in function parse_url


$url = 'http://www.example.com?id=example.id&v=other.variable';
parse_str(parse_url($url, PHP_URL_QUERY), $vars);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜