Home >Backend Development >PHP Tutorial >ip地址怎么转换为IPCDBL

ip地址怎么转换为IPCDBL

WBOY
WBOYOriginal
2016-06-13 10:57:441066browse

ip地址如何转换为IPCDBL
ip地址如何转换为IPCDBL?
如192.168.1.255转换后是3232236031,
求ip转换为ipcdbl的算法和ipcdbl转换为ip的算法

------解决方案--------------------

PHP code
<?phpfunction 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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn