Recently to do a decimal number of reversible conversion to do the invitation code, has not figured out how to do it, it is too complicated, today to get IP thought this can be converted, and then studied the following principle:
The main is to organize themselves under:
$ip = ' 12.34.56.78 ';
$ips = Explode ('. ', $ip);
$result = 0;
$result + + $ips [0]<<24;
$result + + $ips [1]<<16;
$result + + $ips [2]<<8;
$result + + $ips [3];
Echo Bindec (Decbin ($result));
Echo '
';
Echo Bindec (Decbin (Ip2long ($IP)));
Echo '
';
$str = ';
$str. = Intval ($result/intval (POW (2)).
$str. = Intval (($result &0x00ffffff)/intval (POW (2)).
$str. = Intval (($result &0x0000ffff)/intval (POW (2, 8)).
$str. = Intval ($result &0x000000ff);
echo $str;
Echo '
';
echo Long2ip ($result);
The results of the above output are:
203569230
203569230
12.34.56.78
12.34.56.78
It's just a way to achieve it, and there are other ways.
I would like to use a similar method, you can directly convert a decimal number to other decimal values and reversible, but encountered a number of 0 in the middle of the number of problems found too much, such as 1000100