ip2long
is very useful in this case:
$ipAddress = "8.8.8.8";
echo decbin(ip2long($ipAddress));
Also, note that decbin()
won't always output the same number of digits, so try using sprintf()
instead to always get 32 bits:
sprintf("%032b", ip2long($ipAddress));