-
-
$ip = "182.18.8.196";
- echo '
';
- echo ip2long($ip);
- echo " @ ";
- echo $ipfu = ip2int($ ip);
- echo ' @ ';
- $ip_n = bindec(decbin(ip2long($ip)));
- echo $ip_n;
- echo ' @ ';
- echo long2ip($ip_n);
- echo ' @ ';
- echo long2ip($ipfu);//Convert numbers to IP
//You can directly use this function to get the number converted from the IP address.
- function myip2long($ip){
- return bindec(decbin(ip2long($ip)));
- }
//This function is equivalent to ip2long
- function ip2int($ip){
- list($ip1,$ip2,$ip3,$ip4)=explode(".",$ip);
- return ($ip1<<24)|($ip2<<16)|($ip3<< ;8)|($ip4);
- }
-
Copy the code
This way you can get the correct result:
-1240332092 @ -1240332092 @ 3054635204 @ 182.18.8.196 @ 182.18.8.196
3054635204
Directly call the myip2long function to get a positive number.
Articles you may be interested in:
php code to realize IP address and number exchange
|