Splitting up dynamic string in PHP

burg93

I have the following string in PHP:

System load: 0.0 Processes: 119 Usage of /: 0.8% of 226.04GB Users logged in: 1 Memory     usage: 4% IP address for eth0: 192.168.0.21 Swap usage: 0% Graph this data and manage this system at https://landscape.canonical.com/ 

I'm trying to split it up into strings for each value so I can get "0.0", "119", "0.8% of 226.04GB", "1", "4%", "192.168.0.21", "0%".

I did try using set locations in the string to pick out the data but realised it was no good as the values are dynamic and could change from being 1 to 4+ characters long at any time. Is there a way I can split these up using PHP? I was unable to find anything in the string function library. Thanks.

bagonyi

http://www.phpliveregex.com/p/2kT

$input = 'System load: 0.0 Processes: 119 Usage of /: 0.8% of 226.04GB Users logged in: 1 Memory     usage: 4% IP address for eth0: 192.168.0.21 Swap usage: 0% Graph this data and manage this system at https://landscape.canonical.com/';

$results = array();

preg_match_all("/\d[^\s:]*/", $input, $results);

$results will look like this:

Array
(
    [0] => Array
        (
            [0] => 0.0
            [1] => 119
            [2] => 0.8%
            [3] => 226.04GB
            [4] => 1
            [5] => 4%
            [6] => 0
            [7] => 192.168.0.21
            [8] => 0%
        )

)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related