kaf3773 Posted January 24, 2013 Share Posted January 24, 2013 Hi I have a php script that executes a command to get the following results below I will appreciate it very much if you can help me with a php preg_match that can pick the percentage in the second column based on the supplied queue number in the first column Thanks in advance. ================================================================== QUEUE USAGE TOTAL book1 book2 ------------------------------------------------------------------ 0001 18% 822 481 98 0002 16% 345 765 88 0003 10% 400 300 166 0004 15% 994 322 177 0005 17% 348 297 131 ---------------------------------------------------------- Quote Link to comment https://forums.phpfreaks.com/topic/273594-preg_match-picking-values-from-a-table/ Share on other sites More sharing options...
requinix Posted January 24, 2013 Share Posted January 24, 2013 Try feeding /^(\d+)\s+(\d+)%/m to preg_match_all(). Quote Link to comment https://forums.phpfreaks.com/topic/273594-preg_match-picking-values-from-a-table/#findComment-1407987 Share on other sites More sharing options...
kaf3773 Posted January 24, 2013 Author Share Posted January 24, 2013 i tried it like you said where $content is a variable that holds the results of the table. preg_match_all('/^(\d+)\s+(\d+)%/m', $content, $match, PREG_PATTERN_ORDER); print_r($match[0]); This is what is printed out after runing the code. Help will really be appreciated Array ( ) Quote Link to comment https://forums.phpfreaks.com/topic/273594-preg_match-picking-values-from-a-table/#findComment-1408006 Share on other sites More sharing options...
requinix Posted January 24, 2013 Share Posted January 24, 2013 <?php $content = <<<TEXT QUEUE USAGE TOTAL book1 book2 ------------------------------------------------------------------ 0001 18% 822 481 98 0002 16% 345 765 88 0003 10% 400 300 166 0004 15% 994 322 177 0005 17% 348 297 131 ---------------------------------------------------------- TEXT; preg_match_all('/^(\d+)\s+(\d+)%/m', $content, $match, PREG_PATTERN_ORDER); print_r($match); Array ( [0] => Array ( [0] => 0001 18% [1] => 0002 16% [2] => 0003 10% [3] => 0004 15% [4] => 0005 17% ) [1] => Array ( [0] => 0001 [1] => 0002 [2] => 0003 [3] => 0004 [4] => 0005 ) [2] => Array ( [0] => 18 [1] => 16 [2] => 10 [3] => 15 [4] => 17 ) ) Quote Link to comment https://forums.phpfreaks.com/topic/273594-preg_match-picking-values-from-a-table/#findComment-1408029 Share on other sites More sharing options...
kaf3773 Posted January 24, 2013 Author Share Posted January 24, 2013 Thank you so much requinix I really appreciate this. How can i print out the items in the Array on their own. For instance how can i get just 18 16 10 15 17 [2] => Array ( [0] => 18 [1] => 16 [2] => 10 [3] => 15 [4] => 17 ) Thanks Quote Link to comment https://forums.phpfreaks.com/topic/273594-preg_match-picking-values-from-a-table/#findComment-1408061 Share on other sites More sharing options...
requinix Posted January 24, 2013 Share Posted January 24, 2013 Well, it's right there in the main array so $match[2] Quote Link to comment https://forums.phpfreaks.com/topic/273594-preg_match-picking-values-from-a-table/#findComment-1408067 Share on other sites More sharing options...
kaf3773 Posted January 24, 2013 Author Share Posted January 24, 2013 Thanks so much this worked out great Quote Link to comment https://forums.phpfreaks.com/topic/273594-preg_match-picking-values-from-a-table/#findComment-1408077 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.