What is the best way to extract and display the domain name from a URL in PHP?

To extract and display the domain name from a URL in PHP, you can use the parse_url() function to break down the URL into its components and then extract the host component. This will give you the domain name without the protocol or any path information. You can then display the extracted domain name as needed.

$url = "https://www.example.com/path/to/page";
$domain = parse_url($url, PHP_URL_HOST);
echo $domain;