ip2long() - php 网络函数
ip2long()
(PHP 4, PHP 5, PHP 7)
将 IPV4 的字符串互联网协议转换成长整型数字
说明
ip2long(string $ip_address): int函数ip2long()返回 IPV4 网络地址的长整型格式,从标准网络地址格式(点字符串)转化得到。
ip2long()还可以与非完整IP进行工作。阅读» http://publibn.boulder.ibm.com/doc_link/en_US/a_doc_lib/libs/commtrf2/inet_addr.htm获得更多信息。
参数
$ip_address一个标准格式的地址。
返回值
返回IP地址转换后的数字或FALSE
如果$ip_address是无效的。
更新日志
版本 | 说明 |
---|---|
5.5.0 | Prior to this version, on Windowsip2long()would sometimes return a valid number even if passed a value which was not an (IPv4) Internet Protocol dotted address. |
5.2.10 | 再此之前的版本,ip2long()有时会返回即使这不是一个IPV4的标准地址的数字地址。 |
范例
Example #1ip2long()例子
显示IP地址
第二个例子说明打印一个转换后的地址使用printf()在PHP4和PHP5的功能:
注释
Note:因为PHP的integer类型是有符号,并且有许多的IP地址讲导致在32位系统的情况下为负数,你需要使用"%u"进行转换通过sprintf()或printf()得到的字符串来表示无符号的IP地址。Note:
ip2long()将返回FALSE
在IP是255.255.255.255的情况,版本为 PHP 5
The manual states that "ip2long() will also work with non-complete IP addresses", however this is system-dependant so cannot be relied upon. For example, on my system ip2long() will return FALSE for incomplete addresses: This is because ip2long will use inet_pton if available, which does not support non-complete addresses. If inet_pton is not available on your system, inet_addr will be used and incomplete addresses will work as stated.
To nate, who advises that there is no reason to use an unsigned version of the IP in a MySQL DB: I think it would depend on your application, but personally, I find it useful to store IP's as unsigneds since MySQL has 2 native functions, INET_ATON() and INET_NTOA(), which work the same as ip2long()/long2ip() _except_ that they generate the unsigned counterpart. So if you want, you could do: -- IANA Class-B reserved/private SELECT * FROM `servers` WHERE `ip` >= INET_ATON('192.168.0.0') AND `ip`
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)