get domain name in php – How to get current page URL in PHP? All PHP code are group together in getDomain() function.
Table of Contents
get domain name in php
In order to get the domain name from a URL, you can use the parse_url() method and host parameter. also you can more details for get domain name in php
php get current domain
[php]
[/php]
[php]
$currentDomain = $_SERVER[‘SERVER_NAME’];
[/php]
Don’t Miss : PHP GET_HEADERS
php get domain from url
[php]
$url = ‘https://www.itsolutionstuck.com/how-to-send-attachment-in-mail-in-php.html’;
$parse = parse_url($url);
echo $parse[‘host’]; // prints ‘itsolutionstuck.com’
[/php]
php get domain name from url
[php]
parse_url(‘http://www.website.com/hey.php’, PHP_URL_HOST);
[/php]
How to Get Domain Name from URL in PHP?
[php]
function getDomain($url){
$pieces = parse_url($url);
$domain = isset($pieces[‘host’]) ? $pieces[‘host’] : ”;
if(preg_match(‘/(?P
return $regs[‘domain’];
}
return FALSE;
}
echo getDomain(“https://itsolutionstuck.com”); // results ‘itsolutionstuck.com’
echo getDomain(“https://www.itsolutionstuck.com”); // results ‘itsolutionstuck.com’
echo getDomain(“http://mail.itsolutionstuck.co.uk”); // results ‘itsolutionstuck.co.uk’
[/php]