1
2<?php
3$url = 'http://username:password@hostname:9090/path?arg=value#anchor';
4
5var_dump(parse_url($url));
6var_dump(parse_url($url, PHP_URL_SCHEME));
7var_dump(parse_url($url, PHP_URL_USER));
8var_dump(parse_url($url, PHP_URL_PASS));
9var_dump(parse_url($url, PHP_URL_HOST));
10var_dump(parse_url($url, PHP_URL_PORT));
11var_dump(parse_url($url, PHP_URL_PATH));
12var_dump(parse_url($url, PHP_URL_QUERY));
13var_dump(parse_url($url, PHP_URL_FRAGMENT));
14
15
1 //https://www.google.com/search?key=1234
2 $url = $_SERVER['REQUEST_URI'];
3 $url_components = parse_url($url);
4 parse_str($url_components['query'], $params);
5 $key = $params['key'];
6
7// key=1234