Home > php教程 > php手册 > body text

ip地址和int相互转换

WBOY
Release: 2016-06-06 19:38:50
Original
1567 people have browsed it

ip地址和int相互转换 无 function ip_to_int($ip,$reverse=false){ if($reverse){ $ipVal = (int)$ip; $ipArr[0] = floor($ipVal / 0x1000000); $ipVint = $ipVal-($ipArr[0]*0x1000000); $ipArr[1] = ($ipVint 0xFF0000) 16; $ipArr[2] = ($ipVint 0xFF00 )

ip地址和int相互转换
function ip_to_int($ip,$reverse=false){
    if($reverse){
        $ipVal = (int)$ip;
        $ipArr[0] = floor($ipVal / 0x1000000);
        $ipVint   = $ipVal-($ipArr[0]*0x1000000);
        $ipArr[1] = ($ipVint & 0xFF0000)  >> 16;
        $ipArr[2] = ($ipVint & 0xFF00  )  >> 8;
        $ipArr[3] =  $ipVint & 0xFF;
        $ipDotted = implode('.', $ipArr);
        return $ipDotted;
    }

    $ipArr  =   explode('.',$ip);

    $ipInt  =   ($ipArr[0] << 24)
                + ($ipArr[1] << 16)
                + ($ipArr[2] << 8)
                + ($ipArr[3]);
    return $ipInt;

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