Page 1 of 1

PHP string filtering?...

Posted: Tue Nov 26, 2002 8:04 pm
by mandrake
what I'm trying to develop is a php script that will pull the packets(RX/TX) from each of my interfaces on my router. I will then use the number of packets as variables in a Flash file...I'm new to php, but rapidly learning...so far I'm managed to come up with a php script that will get the results I need...the only problem is I want ONLY the number of packets, take a look:

<?php

exec("ifconfig eth0", $results);
echo $results[3];

?>

and the Output:
RX packets:587787 errors:0 dropped:0 overruns:0

what I need is the packets number(587787) and nothing else...I've tried using filters, chunk and matching and haven't come up with anything...does anyone have any ideas to help me...would be MUCH appreciated! :P

Posted: Tue Nov 26, 2002 8:13 pm
by volka
e.g. with preg_match

Code: Select all

$pattern = '!.*packets:(\d*)\s.*!';
preg_match($pattern, $results&#1111;3], $packetNum);

Posted: Tue Nov 26, 2002 8:26 pm
by mandrake
I'm still getting the same output...the packet numbers should be stored in $packetNum right?

Posted: Tue Nov 26, 2002 10:02 pm
by volka
$packetNum should be an array (wether the pattern works or not)
if preg_match return != 0 then $packetNum[1] should contain the result.
try

Code: Select all

print_r($packetNum);
to see what's in.