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;
    }