I have the current code
$trace = exec("tracert 192.168.0.1", $outcome, $status);
print_r($outcome);
which is outputting an array like this:
Array ( [0] => [1] => Tracing route to 192.168.0.1 over a maximum of 30 hops [2] => [3] => 1 <1 ms <1 ms <1 ms 192.168.1.1 [4] => 2 5 ms 4 ms 4 ms 192.168.0.1 [5] => [6] => Trace complete. )
Now what I specifically want to get at is the latency values (ms) in elements 3 and 4. I can get these using print_r($outcome[3]) for example which outputs:
1 <1 ms <1 ms <1 ms 192.168.1.1
However all I want from this is the ‘<1ms <1ms <1ms‘ bit.
What would be the best way to get just this? Bearing in mind that this is just an example and these values are subject to change.
Would appreciate any advice or input! Thanks 🙂
Use a regular expression:
Confirmed here.