Two practical ways to convert IP addresses into decimal numbers in PHP _php instances
Source: Internet
Author: User
How do you turn IP addresses into decimal numbers in PHP? Now there are many times in PHP to use the IP address, but this IP address is not available when the 10 binary. Then how to translate the IP address into decimal number in PHP is our headache, the following two methods are my processing to a relatively simple IP address to the decimal number method. Hope to be helpful to everyone.
Method One: Copy the Code code as follows:
Public Function Iptolong () {
$ip = $_server[' remote_addr ');
$ip = Explode ('. ', $IP);
$ip = Array_reverse ($IP);//Array inversion
$r = 0;
For ($i =0, $j =count ($IP), $i < $j; $i + +) {
$r + = $ip [$i] * POW ($i);
}
$r = sprintf ("%u", $r);
Echo $r;
}
Two results in the local server, the result is 3232235877, the IP used is 192.168.1.101. We tested it with ping 192.168.1.101 and ping 3232235877来 to see if it was the same.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.