ip地址如何转换为IPCDBL
ip地址如何转换为IPCDBL?
如192.168.1.255转换后是3232236031,
求ip转换为ipcdbl的算法和ipcdbl转换为ip的算法
------解决方案--------------------
<?php function iptolong($ip){ $key = explode('.', $ip); if(count($key) >= 4){ $long = intval($key[0]) * 16777216 + intval($key[1]) * 65536 + intval($key[2]) * 256 + intval($key[3]); } return $long; } function longtoip($long){ $long = floor($long); $p4 = $long - floor($long / 256) * 256; $long = ($long - $p4) / 256; $p3 = $long - floor($long / 256) * 256; $long = ($long - $p3) / 256; $p2 = $long - floor($long / 256) * 256; $long = ($long - $p2) / 256; $p1 = $long; $ip = $p1.'.'.$p2.'.'.$p3.'.'.$p4; return $ip; } ?> <div class="clear"> </div>