IP2Location.php
private static function ipVersionAndNumber($ip) {
    if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
      return [4, sprintf('%u', ip2long($ip))];
    } elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
	  $result = 0;

	  foreach (str_split(bin2hex(inet_pton($ip)), 8) as $word) {
        $result = bcadd(bcmul($result, '4294967296', 0), self::wrap32(hexdec($word)), 0);
      }

	  return [6, $result];
    } else {
      // Invalid IP address, return falses
      return [false, false];
    }
  }
private static function ipVersionAndNumber($ip) {
    if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
      return [4, sprintf('%u', ip2long($ip))];
    } elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
	  $result = 0;

	  foreach (str_split(bin2hex(inet_pton($ip)), 8) as $word) {
        $result = bcadd(bcmul($result, '4294967296', 0), self::wrap32(hexdec($word)), 0);
      }

	  return [6, $result];
    } else {
      // Invalid IP address, return falses
      return [false, false];
    }
  }
private static function ipVersionAndNumber ( $ ip ) { if ( filter_var ( $ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 ) ) { return [ 4 , sprintf ( '%u' , ip2long ( $ ip ) ) ] ; } elseif ( filter_var ( $ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 ) ) { $ result = 0 ; foreach ( str_split ( bin2hex ( inet_pton ( $ ip ) ) , 8 ) as $ word ) { $ result = bcadd ( bcmul ( $ result , '4294967296' , 0 ) , self :: wrap32 ( hexdec ( $ word ) ) , 0 ) ; } return [ 6 , $ result ] ; } else { // Invalid IP address, return falses return [ false , false ] ; } }
Get the IP version and number of the given IP address

This method will return an array, whose components will be:
- first: 4 if the given IP address is an IPv4 one, 6 if it's an IPv6 one,
or fase if it's neither.
- second: the IP address' number if its version is 4, the number string if
its version is 6, false otherwise.

@access private
@static
@param string $ip  IP address to extract the version and number for
@return array
Get the IP version and number of the given IP address