Drezard Posted October 28, 2008 Share Posted October 28, 2008 <?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 More sharing options...
DarkWater Posted October 28, 2008 Share Posted October 28, 2008 $returnarray = preg_split('/\s+/', $return); Link to comment https://forums.phpfreaks.com/topic/130363-spaces/#findComment-676231 Share on other sites More sharing options...
Drezard Posted October 28, 2008 Author Share Posted October 28, 2008 The code: $return = exec('df'); Only returns the last line. How do I get it to return EVERY line? I want all of the info from the df command. Daniel Link to comment https://forums.phpfreaks.com/topic/130363-spaces/#findComment-676254 Share on other sites More sharing options...
DarkWater Posted October 28, 2008 Share Posted October 28, 2008 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 More sharing options...
trq Posted October 28, 2008 Share Posted October 28, 2008 Only returns the last line. How do I get it to return EVERY line? Use shell_exec instead of exec. Link to comment https://forums.phpfreaks.com/topic/130363-spaces/#findComment-676264 Share on other sites More sharing options...
Jeremysr Posted October 28, 2008 Share Posted October 28, 2008 For me, exec('df') only displays one line but passthru('df') displays all of them. So try using passthru(). (It prints the output by default, or copies the output into a string variable if you give the variable as the second argument.) Link to comment https://forums.phpfreaks.com/topic/130363-spaces/#findComment-676265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.