Home  >  Article  >  php教程  >  IP2Long和Long2IP函数的PHP实现

IP2Long和Long2IP函数的PHP实现

PHP中文网
PHP中文网Original
2016-05-25 17:06:191228browse

php代码:

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.&#39;.&#39;.$ip2.&#39;.&#39;.$ip3.&#39;.&#39;.$ip4;
}
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