略微加速

略速 - 互联网笔记

PHP根据URL获取IP

2021-11-02 leiting (1739阅读)

标签 PHP

gethostbyname

(PHP 4, PHP 5, PHP 7)

gethostbyname — 返回主机名对应的 IPv4地址。

说明

gethostbyname ( string $hostname ) : string

返回主机名 hostname 对应的 IPv4 互联网地址。

参数


  • hostname

  • 主机名

返回值

成功时返回 IPv4 地址,失败时原封不动返回 hostname 字符串。

范例


Example #1 简单的 gethostbyname() 例子

<?php
$ip = gethostbyname('www.example.com');

echo $ip;
?>

参见


  • gethostbyaddr() - 获取指定的IP地址对应的主机名

  • gethostbynamel() - 获取互联网主机名对应的 IPv4 地址列表

  • inet_pton() - Converts a human readable IP address to its packed in_addr representation

  • inet_ntop() - Converts a packed internet address to a human readable representation


北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3