You are here

function _field_ipaddress_ip2long in IP address fields 7

Convert IP address in decimal form to long.

A wrapper around ip2long that ignores any leading zeros in each octet. Normally a leading zero will cause ip2long (and many other tools) to interpret the octet as an octal number. See for example http://support.microsoft.com/kb/115388

File

./field_ipaddress.module, line 447

Code

function _field_ipaddress_ip2long($ip) {
  $octets = explode(".", $ip);
  $ip = "";
  $dot = "";
  while (list($key, $val) = each($octets)) {
    $ip = sprintf("%s%s%d", $ip, $dot, $val);
    $dot = ".";
  }
  return ip2long($ip);
}