Passed
Push — master ( 48be32...e84af2 )
by Tim
02:19
created

test.php (1 issue)

Labels
Severity
1
<?php
2
3
function ip2bin($ip)
4
{
5
    if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false)
6
        return base_convert(ip2long($ip),10,2);
7
    if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false)
8
        return false;
9
    if(($ip_n = inet_pton($ip)) === false) return false;
10
    $bits = 15;
11
    $ipbin = '';
12
    while ($bits >= 0) {
13
        $bin = sprintf("%08b",(ord($ip_n[$bits])));
14
        $ipbin = $bin.$ipbin;
15
        $bits--;
16
    }
17
    return $ipbin;
18
}
19
20
echo ip2bin('4ffe:2900:5545:3210:2000:f8ff:fe21:67cf');
0 ignored issues
show
Are you sure ip2bin('4ffe:2900:5545:3210:2000:f8ff:fe21:67cf') of type false|string can be used in echo? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

20
echo /** @scrutinizer ignore-type */ ip2bin('4ffe:2900:5545:3210:2000:f8ff:fe21:67cf');
Loading history...
21
22
// Outputs:
23
// 01001111111111100010100100000000010101010100010100110010000100000010000000000000111110001111111111111110001000010110011111001111
24