Home >php教程 >php手册 >php不常用ip转换函数与实例应用

php不常用ip转换函数与实例应用

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-02 09:14:141106browse

不看不知道一看吓一跳啊,在ip转换中在php中居然有函数,可以把ip转换整数,同样也要反过来转换,实例代码如下:

$ip="127.0.0.1";  //定义ip地址 
$long=ip2long($ip);  //转换ip地址为整数 
if($long==-1||$long===false)  //如果执行错误 
{ 
    echo 'invalid ip, please try again'; //输出错误信息 
} 
else 
{ 
    echo $ip  . "n"; //192.0.26.166 
    echo "<br>"; 
    echo $long . "n"; // -1073732954 
    printf("%un", ip2long($ip));  // 3221234342 
}
// 
$ip="127.0.0.1";           //定义ip地址 
$long=ip2long($ip);           //转换ip地址为整数 
if($long==-1||$long===false)         //如果执行错误 
{ 
    echo &#39;invalid ip, please try again&#39;;        //输出错误信息 
} 
else 
{ 
    echo $ip  . "n";           //192.0.26.166 
    echo "<br>"; 
    echo $long . "n";           // -1073732954 
    printf("%un", ip2long($ip));         // 3221234342 
} 
//再给一个常用字实例 
$number="2130706433";        //定义数值 
$ip=long2ip($number);        //转换为ip地址形式:127.0.0.1 
echo $ip;


本文地址:

转载随意,但请附上文章地址:-)

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