How to converts 32bit IPv4, or 128bit IPv6 address into human readable address string in PHP

2 Answers

0 votes
$packed = chr(127) . chr(0) . chr(0) . chr(1);
$s = inet_ntop($packed);

echo $s;


/*
run: 

127.0.0.1 

*/

 



answered Jun 29, 2016 by avibootz
0 votes
$packed = str_repeat(chr(0), 15) . chr(1);
$s = inet_ntop($packed);

echo $s;


/*
run: 

::1 

*/

 



answered Jun 29, 2016 by avibootz
...