I would like to parse the output of the ping command in Linux. My current code is working fine, the only problem is, that it only parse the first result. I would like to change it to parse every line.
The red marked lines should also be parsed: https://i.imgur.com/GDE19Xl.png What do I have to change to do that?
That's my current regular expression: https://regex101.com/r/uH0XwP/1
That's the current PHP code:
$re = '/^PING\b[^(]*\(([^)]*)\)\s([^.]*)\..*?^(\d+\sbytes).*?icmp_seq=(\d+).*?ttl=(\d+).*?time=(.*?ms).*?(\d+)\spackets\stransmitted.*?(\d+)\sreceived.*?(\d+%)\spacket\sloss.*?time\s(\d+ms).*?=\s([^\/]*)\/([^\/]*)\/([^\/]*)\/(.*?)\sms/ims';
$str = 'PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
64 bytes from 1.1.1.1: icmp_seq=1 ttl=58 time=0.816 ms
64 bytes from 1.1.1.1: icmp_seq=2 ttl=58 time=0.883 ms
64 bytes from 1.1.1.1: icmp_seq=3 ttl=58 time=0.743 ms
64 bytes from 1.1.1.1: icmp_seq=4 ttl=58 time=0.613 ms
--- 1.1.1.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3033ms
rtt min/avg/max/mdev = 0.613/0.763/0.883/0.105 ms
';
preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 0);
// Print the entire match result
var_dump($matches);
Thank a lot. With best regards