FOF30\Utils\Ip::inet_to_bits PHP Метод

inet_to_bits() защищенный статический Метод

Converts inet_pton output to bits string
protected static inet_to_bits ( string $inet ) : string
$inet string The in_addr representation of an IPv4 or IPv6 address
Результат string
    protected static function inet_to_bits($inet)
    {
        if (strlen($inet) == 4) {
            $unpacked = unpack('A4', $inet);
        } else {
            $unpacked = unpack('A16', $inet);
        }
        $unpacked = str_split($unpacked[1]);
        $binaryip = '';
        foreach ($unpacked as $char) {
            $binaryip .= str_pad(decbin(ord($char)), 8, '0', STR_PAD_LEFT);
        }
        return $binaryip;
    }