$url = 'https://www.example.com/path/to/file.php'; $host = JURI::getInstance()->getHost($url); echo $host; // Output: www.example.com
$current_url = JURI::getInstance()->toString(); $host = JURI::getInstance()->getHost($current_url); echo $host; // Output: www.example.comIn this example, we are using JURI to retrieve the current URL of the page. We then pass this URL to the getHost() method to extract the hostname. The output of this example will be the same as Example 1. Package library: Joomla\CMS\Uri\Uri.