PHP implementation of the method to get the domain name summary, PHP get domain name Summary _php Tutorial

Source: Internet
Author: User

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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.