-2
    <?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

AMC
  • 2,642
  • 7
  • 13
  • 35
  • Well actually this is @jonavon [code](https://stackoverflow.com/a/5858676/2310830) – RiggsFolly Apr 15 '20 at 14:51
  • Stack Overflow is not the place for this. Please see [ask], [help/on-topic]. – AMC Apr 15 '20 at 18:16
  • Does this answer your question? [Getting list IPs from CIDR notation in PHP](https://stackoverflow.com/questions/4931721/getting-list-ips-from-cidr-notation-in-php) – Karthik Apr 15 '20 at 20:16

1 Answers1

1

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>'
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149