Valleriani
asked on
PHP: Parsing a block of text properly and getting uptime
I will attach the block of text.
I can get the information at the console, and normally I can parse things using regexp (For example with XML you can do something like: "$found = preg_match('#<findthis(?:\ s+[^>]+)?> (.*?)'. '</findthis>#s', $result, $matches2);"
I'm having issues though with this one as there is no simple beginning/end..
The line I'm looking to grab is near Uptime 90 0:00:03.. What I want to actually grab in general is "0:00:03"
The issue is however, the text is parsed to be positioned properly. So the text between each area may be different spacing. For example it could be
Uptime 90 0:00:03 .. or maybe:
Uptime 0 0:00:03
Different spacing but same information. I believe its all spaces though. I'm also not 100% sure to 'grab' the 0:00:03 in general too this way.
Does anyone have any ideas? Thanks!
I can get the information at the console, and normally I can parse things using regexp (For example with XML you can do something like: "$found = preg_match('#<findthis(?:\
I'm having issues though with this one as there is no simple beginning/end..
The line I'm looking to grab is near Uptime 90 0:00:03.. What I want to actually grab in general is "0:00:03"
The issue is however, the text is parsed to be positioned properly. So the text between each area may be different spacing. For example it could be
Uptime 90 0:00:03 .. or maybe:
Uptime 0 0:00:03
Different spacing but same information. I believe its all spaces though. I'm also not 100% sure to 'grab' the 0:00:03 in general too this way.
Does anyone have any ideas? Thanks!
Traffic ------------inbound------------ ------------outbound-----------
rcpts msgs kbytes rcpts msgs kbytes
Total 0 0 0.0 0 0 0.0
Last Hour 0 0 0.0 0 0 0.0
Top/Hour 0 0 0.0 0 0 0.0
Last Min. 0 0 0.0 0 0 0.0
Top/Min. 0 0 0.0 0 0 0.0
Connections active top maximum Domain cached pending
Inbound 0 0 30 Names 0 0
Outbound 0 0 1200
Queues rcpts domains kbytes Spool in use recycled
SMTP 0 0 0.0 Files 0 0
other 0 0 0.0 Init. complete
Status running Started 2010-09-16 16:02:08 Uptime 90 0:00:03
ASKER
Hey there,
When I am using:
$found = preg_match('(?<=Uptime)[\s ]*([\d]+[\ s]*([\d]{1 }|[\d]{2}) :[\d]{2}:[ \d]{2})', $result, $matches);
It gives me:
PHP Warning: preg_match(): Unknown modifier '['
When I am using:
$found = preg_match('(?<=Uptime)[\s
It gives me:
PHP Warning: preg_match(): Unknown modifier '['
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nice solutions guys, thanks!
(?<=Uptime)[\s]*([\d]+[\s]
or this (more generic):
(?<=Uptime)[\s]*([\d]+[\s]
Cheers