You can use the parse_url
built-in PHP method to break down a URL into its components.
here's the method itself.
parse_url(string $url, int $component = -1): int|string|array|null|false
And here's how to use it.
parse_url("https://gettingsimple.com/podcast");
// [
// "scheme" => "https",
// "host" => "gettingsimple.com",
// "path" => "/podcast",
// ]
You can then obtain the scheme
, host
, or path
of a URL.
$components = parse_url("https://gettingsimple.com/podcast");
$scheme = $components["scheme"];
// "https"
$host = $components["host"];
// "gettingsimple.com"
$path = $components["path"];
// "/podcast"