Jump to content

Spaces


Drezard

Recommended Posts


<?php

$return = exec('df');

$returnarray = explode(' ', $return);

?>

 

it has FARR too many spaces the $returnarray because

df returns something along the lines of:

 

 

#df

Filesystem          1K-blocks      Used      Available  Use% Mounted on

/dev/sda1            36622412  1464540  33297548    5%        /

 

 

how would i take out all of the spaces???? in the array so instead it would be like $return array[0] = 'Filesystem'; and $returnarray[6] = '/dev/sda'; and $returnarray[7] = '36622412';

 

How would i do this???

 

Link to comment
https://forums.phpfreaks.com/topic/130363-spaces/
Share on other sites

This code seems to work for me:

 

<?php
$return_array = preg_split('/\s+/', `df`);
print_r($return_array);
?>

And if you wanted it arranged slightly more conveniently, you could always do like:

<?php
$lines = explode("\n", `df`);
foreach ($lines as $v) {
    $fixed[] = preg_split('/\s+/', $v);
}
print_r($fixed);
?>

Link to comment
https://forums.phpfreaks.com/topic/130363-spaces/#findComment-676258
Share on other sites

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.