im taking an array of ip ranges:
rangeStart|rangeStop
exploding it into individual /24's
<?php
foreach($rangesLong as $range)
{
if(stripos($range,':') === false) //IPV4
{
$tmp = explode('|',$range);
list($a,$b,$c,$d) = explode('.',$tmp[0]); //RANGE START
list($w,$x,$y,$z) = explode('.',$tmp[1]); //RANGE STOP
//CALC DIFFERENCES FOR EACH 8-BIT
$dA = $w - $a;
$dB = $x - $b;
$dC = $y - $c;
$dD = $z - $d;
$xml = '<?xml version="1.0" encoding="UTF-8" ?>'."\r\n";
$xml .= "<nets>\r\n";
for($i=$a;$i<=$a + $dA;$i++)
{
for($j=$b;$j<=$b + $dB;$j++)
{
for($k=$c;$k<=$c + $dC;$k++)
{
$xml .= "<net>$i.$j.$k.0</net>";
}
}
}
$xml .= '</nets>';
file_put_contents('nets.xml',$xml);
}}
?>
my issue is this line on the inner-most for loop (or so I think):
$xml .= "<net>$i.$j.$k.0</net>";
when i run this, its only displaying the /24's for the last /21 in my original array:
[0] => 0.0.0.0/23
[1] => 0.0.0.0/24
[2] => 0.0.0.0/24
[3] => 0.0.0.0/20
[4] => 0.0.0.0/18
[5] => 0.0.0.0/19
[6] => 0.0.0.0/21
(i do realize this is not the rangeStart|rangeStop array but its just to show the qty im working with)
now, if I change my code to:
echo $xml .= "<net>$i.$j.$k.0</net>";
the browser shows ALL the /24's AND so does the file I'm writing to
how the HECK does echoing the line make it work?
This is going to end up as a cron script the cache results so I could just pipe it to >/dev/null 2>&1
But I'd really like to know why it's behaving so odd