Q:

Convert Array From IP CIDR

    <?php
function cidrToRange($cidr) {
  $range = array();
  $cidr = explode('/', $cidr);
  $range[0] = long2ip((ip2long($cidr[0])) & ((-1 << (32 - (int)$cidr[1]))));
  $range[1] = long2ip((ip2long($range[0])) + pow(2, (32 - (int)$cidr[1])) - 1);
  return $range;
}
var_dump(cidrToRange("104.176.0.0/12"));

//output array "array(2) { [0]=> string(11) "104.176.0.0" [1]=> string(15) "104.191.255.255" }""
?>

can I get data "104.176.0.0" and "104.191.255.255" from the array output?
can you provide the correct php code. thanks

A:

Just put the result of the function call into a variable and then print the parts you want
<?php
function cidrToRange($cidr) {
    $range = array();
    $cidr = explode('/', $cidr);  
    $range[0] = long2ip((ip2long($cidr[0])) & ((-1 << (32 - (int)$cidr[1]))));
    $range[1] = long2ip((ip2long($range[0])) + pow(2, (32 - (int)$cidr[1])) - 1);
    return $range;
}
$range = cidrToRange("104.176.0.0/12");
echo 'Staring at ' . $range[0] .'<br>'
echo 'Ending at '  . $range[1] .'<br>'

