Unix tree convert to recursive php array
- by Fordnox
I have a response from remote server like this:
/home/computer/Downloads
|-- /home/computer/Downloads/Apple
| `-- /home/computer/Downloads/Apple/Pad
|-- /home/computer/Downloads/Empty_Folder
`-- /home/computer/Downloads/Subfolder
|-- /home/computer/Downloads/Subfolder/Empty
`-- /home/computer/Downloads/Subfolder/SubSubFolder
`-- /home/computer/Downloads/Subfolder/SubSubFolder/Test
this is the output for command
computer@athome:$ tree -df --noreport -L 5 /home/computer/Downloads/
I would like to parse this string to recursive php array or object, something like this.
I would show only part of result to get the idea.
array(
'title' => '/home/computer/Downloads',
'children' => array(
0 => array(
'title' => '/home/computer/Downloads/Apple',
'children' => array( ...
)
)
);
Response from server can change according to scanned directory. Can someone help me write this function.
Please note that this is response from remote server and php functions can not scan any remote dir.