I have the following string:
/dev/sda1 ext4 19620732 16936800 1664184
udev devtmpfs 10240 10240 0
tmpfs tmpfs 101232 96740 4492
tmpfs tmpfs 253080 253080 0
tmpfs tmpfs 5120 5120 0
tmpfs tmpfs 253080 253080 0
var 89www vboxsf 487350400 350068644 137281756
I want to pass the string in question to array, so that the final structure is:
Array
(
[0] => Array
(
[sistArq] => /dev/sda1
[tipo] => ext4
[tamanho] => 19620732
[disponivel] => 16936800
[usado] => 1664184
)
[1] => Array
(
[sistArq] => udev
[tipo] => devtmpfs
[tamanho] => 10240
[disponivel] => 10240
[usado] => 0
)
[2] => Array
(
[sistArq] => tmpfs
[tipo] => tmpfs
[tamanho] => 101232
[disponivel] => 96740
[usado] => 4492
)
[3] => Array
(
[sistArq] => tmpfs
[tipo] => tmpfs
[tamanho] => 253080
[disponivel] => 253080
[usado] => 0
)
[4] => Array
(
[sistArq] => tmpfs
[tipo] => tmpfs
[tamanho] => 5120
[disponivel] => 5120
[usado] => 0
)
[5] => Array
(
[sistArq] => tmpfs
[tipo] => tmpfs
[tamanho] => 253080
[disponivel] => 253080
[usado] => 0
)
[6] => Array
(
[sistArq] => var 89www
[tipo] => vboxsf
[tamanho] => vboxsf
[disponivel] => 487350400
[usado] => 350068644
)
)
I tried something like:
$output = trim(preg_replace('/^.+\n/', '', $string));
$output = explode("\n", $output);
$output = preg_replace('/[ ]{1,}/', ' == ' ,$output);
for ($i = 0; $i < sizeof($output); $i++)
{
$campos = explode(" == ", $output[$i]);
$arr[$i] = array(
'sistArq' => $campos[0],
'tipo' => $campos[1],
'tamanho' => $campos[2],
'disponivel' => $campos[3],
'usado' => $campos[4]
);
}
But I did not have the expected success.