Jump to content

preg_match picking values from a table


kaf3773

Recommended Posts

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

 

----------------------------------------------------------

Link to comment
https://forums.phpfreaks.com/topic/273594-preg_match-picking-values-from-a-table/
Share on other sites

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

(

)

<?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
        )

)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.