Created
February 8, 2013 16:54
-
-
Save cschaba/4740323 to your computer and use it in GitHub Desktop.
PHP: parse output of "df -k"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$data = <<<EOF | |
Filesystem 1K-blocks Used Available Use% Mounted on | |
ubi0_0 143180 89740 53440 63% / | |
tmpfs 64 0 64 0% /dev | |
tmpfs 143124 76 143048 0% /tmp | |
tmpfs 4096 912 3184 22% /var | |
tmpfs 64 0 64 0% /mnt | |
ubi1_0 468256 12144 456112 3% /opt/data/settings | |
EOF; | |
print_r(array_map(function($line){ | |
$elements=preg_split('/\s+/',$line); | |
return(array( | |
'filesystem' => $elements[0], | |
'1k-blocks' => $elements[1], | |
'used' => $elements[2], | |
'available' => $elements[3], | |
'use%' => $elements[4], | |
'mounted_on' => $elements[5] | |
)); | |
},explode("\n",$data))); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, you saved me a couple of minutes :)