php IP2Long和Long2IP函数的PHP实现
IP2Long和Long2IP函数的PHP实现 [代码片段(16行)]
function IP2Long($ip) {
$ips = explode('.', $ip);
if(count($ips) != 4) {
return false;
}
return ($ips[0] << 24) + ($ips[1] << 16) + ($ips[2] << 8) + $ips[3];
}
function Long2IP($int) {
$ip1 = $ipint >> 24;
$ip2 = ($ipint >> 16) & 255;
$ip3 = ($ipint >> 8) & 255;
$ip4 = $ipint & 255;
return $ip1.'.'.$ip2.'.'.$ip3.'.'.$ip4;
}
//该片段来自于http://outofmemory.cn
- 上一篇:php 中文截取无乱码的PHP
- 下一篇:PHP curl 抓取AJAX异步内容示例
精彩图集
精彩文章






