รบกวนถามเรื่อง PHP คำสั่ง Ping ครับ

เริ่มโดย tcool, 22 พฤศจิกายน 2015, 10:40:51

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

tcool

สวัสดีครับ

ผมใช้ code นี้อยู่นะครับ

$ip =   "127.0.0.1";
exec("ping -c 4 " . $ip, $output, $result);
print_r($output);

ผลออกมาคือ

Array (
  • => PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data. [1] => 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.035 ms [2] => 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.020 ms [3] => 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.023 ms [4] => 64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.023 ms [5] => [6] => --- 127.0.0.1 ping statistics --- [7] => 4 packets transmitted, 4 received, 0% packet loss, time 2998ms [8] => rtt min/avg/max/mdev = 0.020/0.025/0.035/0.006 ms )

    ผมจะทำอย่างไรได้ให้มันออกมาเป็นแบบนี้ครับ(ตัวอย่าง)

    PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
    64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.040 ms
    64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.021 ms
    64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.023 ms
    64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.023 ms

    --- 127.0.0.1 ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 2998ms
    rtt min/avg/max/mdev = 0.021/0.026/0.040/0.009 ms

    ขอบคุณมากๆ เลยนะครับ

nscyber

ตามนี้ครับลองดูนะครับ

$ip =   "127.0.0.1";
exec("ping -c 4 " . $ip, $output, $result);
$count = count($output);
for($i=0;$i<$count;$i++)
{
  echo $output[$i].'<br>';
}

tcool

ขอบคุณมากๆ เลยครับคุณ nscyber ได้แล้วครับผม

sahawat