Xtremer360 Posted July 30, 2011 Share Posted July 30, 2011 I'm looking for a function or something that when I echo it will return (http://www.whatever.com). Anyone have one handy? Link to comment https://forums.phpfreaks.com/topic/243245-php-domain-function/ Share on other sites More sharing options...
FRSH Posted July 30, 2011 Share Posted July 30, 2011 Could you give a bit more information? <?php $domain = "http://whatever.com"; echo $domain; ?> Link to comment https://forums.phpfreaks.com/topic/243245-php-domain-function/#findComment-1249273 Share on other sites More sharing options...
Xtremer360 Posted July 30, 2011 Author Share Posted July 30, 2011 I thought what I had made sense. I'm looking for a function that when the function is ran will return the full domain of the site your on so if you ran it on here for example it would return (http://www.phpfreaks.com). Link to comment https://forums.phpfreaks.com/topic/243245-php-domain-function/#findComment-1249274 Share on other sites More sharing options...
FRSH Posted July 30, 2011 Share Posted July 30, 2011 <?php function getDomain() { print $_SERVER['HTTP_HOST']; } ?> Call it like this: <?php getDomain(); ?> Link to comment https://forums.phpfreaks.com/topic/243245-php-domain-function/#findComment-1249276 Share on other sites More sharing options...
skwap Posted July 30, 2011 Share Posted July 30, 2011 Try below code.. <?php function sitename() { $result = $_SERVER['HTTP_HOST']; return $result; } ?> Then call the function like <?php echo sitename(); ?> Thank You ! Link to comment https://forums.phpfreaks.com/topic/243245-php-domain-function/#findComment-1249278 Share on other sites More sharing options...
Xtremer360 Posted July 30, 2011 Author Share Posted July 30, 2011 Why is it that it cuts of the http://www. part Link to comment https://forums.phpfreaks.com/topic/243245-php-domain-function/#findComment-1249279 Share on other sites More sharing options...
FRSH Posted July 30, 2011 Share Posted July 30, 2011 Because some people may want a url without a www. Link to comment https://forums.phpfreaks.com/topic/243245-php-domain-function/#findComment-1249281 Share on other sites More sharing options...
QuickOldCar Posted July 30, 2011 Share Posted July 30, 2011 Here's a parse url function that parses the domains url. For the main domain host it gets way more complicated, but I have that as well. <?php function getparsedHost($new_parse_url) { $new_parse_url = str_ireplace(array("https://", "http://", "ftp://", "feed://"), "", trim($new_parse_url)); $parsedUrl = parse_url("http://$new_parse_url"); return "http://".trim($parsedUrl['host'] ? $parsedUrl['host'] : array_shift(explode('/', $parsedUrl['path'], 2))); } $testurl = "http://music.aol.com/new"; echo getparsedHost($testurl); ?> For why it chopped the http:www., just put it back <?php function sitename() { $result = $_SERVER['HTTP_HOST']; return "http://".$result; } ?> Link to comment https://forums.phpfreaks.com/topic/243245-php-domain-function/#findComment-1249282 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.