Originally posted by clam2000:
lets see...
[php]
<?
$count=$HTTP_GET_VARS['count'];
$host=$HTTP_GET_VARS['host'];
$dumpedping=`ping -c $count $host`;
$pingarray=explode('\n',$dumpedping);
// so ping array now has each line... to find the time:
$index=0;
foreach($pingarray as $pingline) {
if($index>0) { // no data on first line
$time[$index]=ereg_replace(" .*","",ereg_replace(".*time=","",$pingline));
}
$index++;
}
// now time is an array with each time in it...
foreach($time as $data) {
echo("time: ".$data);
}
?>
[/php]
does that do what you need?
--will
Thanks for the suggestions, but the code as written above does not work for several reasons. The backtick operator only returns the last line of the output, and the foreach loop with the ereg_replace functions produces an error.
I rewrote it and it now works as well as being slighly more compact.
[php]
<?
$count =$HTTP_GET_VARS ['count'];
$host =$HTTP_GET_VARS ['host'];
exec("ping -c $count $host", $dumpedping);
foreach($dumpedping as $pingline) {
ereg("time=[0-9]+[.]{1}[0-9]+", $pingline, $time);
$pingTime[] = $time[0];
$time[0] = NULL;
}
for($i = 0; $i < count($pingTime); $i++) {
$value = $pingTime[$i];
echo "$value<br />";
}
?>
[/php]