PHP string filtering?...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mandrake
Forum Newbie
Posts: 2
Joined: Tue Nov 26, 2002 8:04 pm

PHP string filtering?...

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

e.g. with preg_match

Code: Select all

$pattern = '!.*packets:(\d*)\s.*!';
preg_match($pattern, $results&#1111;3], $packetNum);
mandrake
Forum Newbie
Posts: 2
Joined: Tue Nov 26, 2002 8:04 pm

Post by mandrake »

I'm still getting the same output...the packet numbers should be stored in $packetNum right?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
Post Reply