How can one extract and analyze the hostname of a URL in PHP?
To extract and analyze the hostname of a URL in PHP, you can use the `parse_url()` function to parse the URL and then access the `host` key in the resulting array to get the hostname. This can be useful for various tasks such as checking if a URL belongs to a specific domain or extracting subdomains.
$url = 'https://www.example.com/path/to/page';
$hostname = parse_url($url, PHP_URL_HOST);
echo $hostname; // Outputs: www.example.com