PHP implementation of the method to get the domain name summary, PHP get the domain name summary
This paper summarizes the method of getting the domain name by PHP implementation. Share to everyone for your reference. The implementation method is as follows:
Method one (with system variables)
The copy Code code is as follows://disadvantage does not use the passed-over address and host that does not support system variables
echo $_server[' Http_host '];
Method Two (with self-function)
Copy the Code code as follows: $url = ' http://www.bkjia.com/index.php?referer=jb51.net ';
$arr _url = Parse_url ($url);
echo $arr _url[' host '];
Method Three (write your own function)
Copy the Code code as follows: function GetDomain ($url)
{
$url = Str_replace (' http://', ', $url); If there is an HTTP prefix, remove the
$pos = Strpos ($url, '/');
if ($pos = = = False)
{
return $url;
}else
{
Return substr ($url, 0, $pos);
}
}
echo GetDomain ($url);
Method four (with regular)
Copy the Code code as follows: Preg_match ("/^" (/http)? ( [^/]+)/I ", $url, $arr _domain);
echo $arr _domain[2];
I hope this article is helpful to everyone's PHP programming.
How to use PHP to get the IP address of the domain name?
gethostbyname (PHP 3, PHP 4, PHP 5)
GetHostByName--Gets the IP address of the specified machine name
Function Format Description:
String gethostbyname (string hostname)
Returns the IP address of the hostname
Example 1. A Simple gethostbyname () example
$ip = gethostbyname (' www.example.com ');
Echo $ip;
?>
PHP Gets an unsolicited domain name
$url = $_server["Http_referer"]; Get the full route URL
$str = Str_replace ("http://", "", $url); Remove/HTTP/
$strdomain = Explode ("/", $STR); Separate the units with "/"
$domain = $strdomain [0]; Take the first "/" previous character
Using the method above is accurate, if you use PHP's own function is not as follows:
$_server[' server_name '] This function gets the server domain name
http://www.bkjia.com/PHPjc/906676.html www.bkjia.com true http://www.bkjia.com/PHPjc/906676.html techarticle PHP Implementation of the method to get the domain name summary, PHP get the domain name summary This article summarizes the PHP implementation method to obtain the domain name. Share to everyone for your reference. The implementation method is as follows: Method ...