Jump to content

PHP Domain Function


Xtremer360

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.