不看不知道一看吓一跳啊,在ip转换中在php中居然有函数,可以把ip转换整数,同样也要反过来转换,实例代码如下:
- $ip="127.0.0.1";
- $long=ip2long($ip);
- if($long==-1||$long===false)
- {
- echo 'invalid ip, please try again';
- }
- else
- {
- echo $ip . "n";
- echo "<br>";
- echo $long . "n";
- printf("%un", ip2long($ip));
- }
-
- $ip="127.0.0.1";
- $long=ip2long($ip);
- if($long==-1||$long===false)
- {
- echo 'invalid ip, please try again';
- }
- else
- {
- echo $ip . "n";
- echo "<br>";
- echo $long . "n";
- printf("%un", ip2long($ip));
- }
-
-
-
- $number="2130706433";
- $ip=long2ip($number);
- echo $ip;
|