private function ip2bin($ip)
    {
        if ($this->getIpVersion($ip) === 4) {
            return str_pad(base_convert(ip2long($ip), 10, 2), static::IPV4_ADDRESS_LENGTH, '0', STR_PAD_LEFT);
        } else {
            $unpack = unpack('A16', inet_pton($ip));
            $binStr = array_shift($unpack);
            $bytes = static::IPV6_ADDRESS_LENGTH / 8; // 128 bit / 8 = 16 bytes
            $result = '';
            while ($bytes-- > 0) {
                $result = sprintf('%08b', isset($binStr[$bytes]) ? ord($binStr[$bytes]) : '0') . $result;
            }
            return $result;
        }
    }
private function ip2bin($ip)
    {
        if ($this->getIpVersion($ip) === 4) {
            return str_pad(base_convert(ip2long($ip), 10, 2), static::IPV4_ADDRESS_LENGTH, '0', STR_PAD_LEFT);
        } else {
            $unpack = unpack('A16', inet_pton($ip));
            $binStr = array_shift($unpack);
            $bytes = static::IPV6_ADDRESS_LENGTH / 8; // 128 bit / 8 = 16 bytes
            $result = '';
            while ($bytes-- > 0) {
                $result = sprintf('%08b', isset($binStr[$bytes]) ? ord($binStr[$bytes]) : '0') . $result;
            }
            return $result;
        }
    }
private function ip2bin ( $ ip ) { if ( $ this -> getIpVersion ( $ ip ) === 4 ) { return str_pad ( base_convert ( ip2long ( $ ip ) , 10 , 2 ) , static :: IPV4_ADDRESS_LENGTH , '0' , STR_PAD_LEFT ) ; } else { $ unpack = unpack ( 'A16' , inet_pton ( $ ip ) ) ; $ binStr = array_shift ( $ unpack ) ; $ bytes = static :: IPV6_ADDRESS_LENGTH / 8 ; // 128 bit / 8 = 16 bytes $ result = '' ; while ( $ bytes -- > 0 ) { $ result = sprintf ( '%08b' , isset ( $ binStr [ $ bytes ] ) ? ord ( $ binStr [ $ bytes ] ) : '0' ) . $ result ; } return $ result ; } }
Converts IP address to bits representation

@param string $ip
@return string bits as a string
Converts IP address to bits representation