$array = file("apache.conf");
$newlinencountered = 0;
$invirtual = 0;
$i = 0;
$j = 0;
while ($i < sizeof($array)) {
// If we are in virtual set it
if($array[$i] == "<VirtualHost>")
$invirtual = 1;
// if we are exiting virtual reset the
// newline and the invirtual
if($array[$i] == "</VirtualHost>") {
$newlinencountered = 0;
$invirtual = 0;
}// end if
// Ok now... if we are in the virtual
// and we run accross a \n character
// then we enter this case and see
// if we have already got a \n
// if no than just put it in our final
// array if yes than dont put it in or
// "delete" it
if($array[$i] == "\n" && $invirtual == 1){
if($newlinencountered != 1)
$final[$j] = $array[$i];
$newlinencountered = 1;
}//end if
else
$final[$j] = $array[$i];
// increment flags
$j++;
$i++;
}// end while
....put array back into the file....
Well this isnt perfect most likely... I hope this is what you want. This should at least give you and idea.
Hope this helps!