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

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

WBOY
Release: 2016-06-02 09:14:14
Original
1049 people have browsed it

不看不知道一看吓一跳啊,在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;
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!