php get url infos

Solutions on MaxInterview for php get url infos by the best coders in the world

showing results for - "php get url infos"
Emie
07 Apr 2017
1$url = 'http://username:password@hostname:9090/path?argument=value#fragment';
2var_dump(parse_url($url, PHP_URL_SCHEME));   // http
3var_dump(parse_url($url, PHP_URL_USER));     // username 
4var_dump(parse_url($url, PHP_URL_PASS));     // password
5var_dump(parse_url($url, PHP_URL_HOST));     // hostname
6var_dump(parse_url($url, PHP_URL_PORT));     // 9090
7var_dump(parse_url($url, PHP_URL_PATH));     // /path
8var_dump(parse_url($url, PHP_URL_QUERY));    // argument=value
9var_dump(parse_url($url, PHP_URL_FRAGMENT)); // fragment
10
11// You can use "parse_str" to parse the URL Query to an Array
12$query = parse_url($url, PHP_URL_QUERY);
13$queryArray = array();
14parse_str($query, $queryArray);
15var_dump($queryArray);  // array('argument' => 'value')
16
17
18
19