How do I parse a URL in PHP? [duplicate]

You can use parse_url to get down to the hostname.

e.g.:

$url = "http://localhost/path/to/?here=there";
$data = parse_url($url);
var_dump($data);

/*
Array
(
    [scheme] => http
    [host] => localhost
    [path] => /path/to/
    [query] => here=there
)
*/

Leave a Comment