Home > php教程 > PHP源码 > body text

IP2Long和Long2IP函数的PHP实现

PHP中文网
Release: 2016-05-25 17:06:19
Original
1227 people have browsed it

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;
}
Copy after login
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template