src/IpTools.php
public function cidrConv($net)
    {
        $start = strtok($net, '/');
        $n = 3 - substr_count($net, '.');

        if ($n > 0) {
            for ($i = $n; $i > 0; $i--) {
                $start .= '.0';
            }
        }

        $bits1 = str_pad(decbin(ip2long($start)), 32, '0', 'STR_PAD_LEFT');
        $net = pow(2, (32 - substr(strstr($net, '/'), 1))) - 1;
        $bits2 = str_pad(decbin($net), 32, '0', 'STR_PAD_LEFT');
        $final = '';

        for ($i = 0; $i < 32; $i++) {
            if ($bits1[$i] == $bits2[$i]) {
                $final .= $bits1[$i];
            }
            if ($bits1[$i] == 1 and $bits2[$i] == 0) {
                $final .= $bits1[$i];
            }
            if ($bits1[$i] == 0 and $bits2[$i] == 1) {
                $final .= $bits2[$i];
            }
        }

        return $start . " - " . long2ip(bindec($final));
    }
public function cidrConv($net)
    {
        $start = strtok($net, '/');
        $n = 3 - substr_count($net, '.');

        if ($n > 0) {
            for ($i = $n; $i > 0; $i--) {
                $start .= '.0';
            }
        }

        $bits1 = str_pad(decbin(ip2long($start)), 32, '0', 'STR_PAD_LEFT');
        $net = pow(2, (32 - substr(strstr($net, '/'), 1))) - 1;
        $bits2 = str_pad(decbin($net), 32, '0', 'STR_PAD_LEFT');
        $final = '';

        for ($i = 0; $i < 32; $i++) {
            if ($bits1[$i] == $bits2[$i]) {
                $final .= $bits1[$i];
            }
            if ($bits1[$i] == 1 and $bits2[$i] == 0) {
                $final .= $bits1[$i];
            }
            if ($bits1[$i] == 0 and $bits2[$i] == 1) {
                $final .= $bits2[$i];
            }
        }

        return $start . " - " . long2ip(bindec($final));
    }
public function cidrConv ( $ net ) { $ start = strtok ( $ net , '/' ) ; $ n = 3 - substr_count ( $ net , '.' ) ; if ( $ n > 0 ) { for ( $ i = $ n ; $ i > 0 ; $ i -- ) { $ start .= '.0' ; } } $ bits1 = str_pad ( decbin ( ip2long ( $ start ) ) , 32 , '0' , 'STR_PAD_LEFT' ) ; $ net = pow ( 2 , ( 32 - substr ( strstr ( $ net , '/' ) , 1 ) ) ) - 1 ; $ bits2 = str_pad ( decbin ( $ net ) , 32 , '0' , 'STR_PAD_LEFT' ) ; $ final = '' ; for ( $ i = 0 ; $ i < 32 ; $ i ++ ) { if ( $ bits1 [ $ i ] == $ bits2 [ $ i ] ) { $ final .= $ bits1 [ $ i ] ; } if ( $ bits1 [ $ i ] == 1 and $ bits2 [ $ i ] == 0 ) { $ final .= $ bits1 [ $ i ] ; } if ( $ bits1 [ $ i ] == 0 and $ bits2 [ $ i ] == 1 ) { $ final .= $ bits2 [ $ i ] ; } } return $ start . " - " . long2ip ( bindec ( $ final ) ) ; }
Convert CIDR to net range

@TODO provide example

@param string $net
@return string
Convert CIDR to net range