you need to use regular expressions
[man]preg_match[/man] or [man]ereg_match[/man]
here is the preg_ solution:
you want to start from 'packets:' and read everything up to the space... i think that would give you want you want
the regular expression to do that would be:
/packets🙁\d+)\s/
so our php call looks like:
preg_match( '/packets🙁\d+)\s/', $result, $matches );
this reads its matches into an array $matches, much like your exec() reads into $results.
and my test code looks like :
<?php
/// exec("ifconfig eth0", $results);
$results = array (
'RX packets:587787 errors:0 dropped:0 overruns:0 ',
'RX packets: errors:0 dropped:0 overruns:0 ',
'RX packets:387787 errors:0 dropped:0 overruns:0 ',
'RX packets: errors:0 dropped:0 overruns:0 ',
'RX packets:287 errors:0 dropped:0 overruns:0 '
);
foreach ( $results as $result ) {
$found = preg_match( '/packets:(\d+)\s/', $result, $matches );
if ( $found ) {
echo "Packets found: {$matches[1]}<br>";
} else {
echo "No packets found in '$result'<br>";
}
}
?>
which shows on my computer
Packets found: 587787
No packets found in 'RX packets: errors:0 dropped:0 overruns:0 '
Packets found: 387787
No packets found in 'RX packets: errors:0 dropped:0 overruns:0 '
Packets found: 287