ip地址怎么转换为IPCDBL

WBOY
Release: 2016-06-13 13:07:01
Original
905 people have browsed it

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

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

PHP code
<?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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!