Jump to content

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
        )

)

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.