ip地址和int相互转换
程序员文章站
2022-05-13 08:45:39
...
ip地址和int相互转换 无 function ip_to_int($ip,$reverse=false){ if($reverse){ $ipVal = (int)$ip; $ipArr[0] = floor($ipVal / 0x1000000); $ipVint = $ipVal-($ipArr[0]*0x1000000); $ipArr[1] = ($ipVint 0xFF0000) 16; $ipArr[2] = ($ipVint 0xFF00 )
ip地址和int相互转换
function ip_to_int($ip,$reverse=false){ if($reverse){ $ipVal = (int)$ip; $ipArr[0] = floor($ipVal / 0x1000000); $ipVint = $ipVal-($ipArr[0]*0x1000000); $ipArr[1] = ($ipVint & 0xFF0000) >> 16; $ipArr[2] = ($ipVint & 0xFF00 ) >> 8; $ipArr[3] = $ipVint & 0xFF; $ipDotted = implode('.', $ipArr); return $ipDotted; } $ipArr = explode('.',$ip); $ipInt = ($ipArr[0]