IPv6 addresses are 128bit, which is 16 bytes/chars. ::1
corresponds to 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:01
, so you're printing 15 null bytes and 0x01, which is not a printable character.
PHP inet_pton returning empty string... var_dump says otherwise
Question
I am trying to save an IPv6 address in a MySQL database. I am using inet_pton
to do this. However, I have noticed that some IP's (in particular this localhost IP) are returning empty strings. Example:
$ip = inet_pton('::1');
And if a do a var_dump
of $ip
it shows that it's length is 16, but nothing is being returned:
var_dump($ip);
// string(16) ""
What is happening here?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow