Parse Directory Structure (Strings) to JSON using PHP
- by Ecropolis
I have an array of file-path strings like this
videos/funny/jelloman.wmv
videos/funny/bellydance.flv
videos/abc.mp4
videos/june.mp4
videos/cleaver.mp4
fun.wmv
jimmy.wmv
herman.wmv
Is there a library or easy way I can get to a data structure json or xml? Something like this: (I see there are a lot of snippets available for traversing actual folders, but again, I just have strings.)
{
files:{
file:[
{
filename:'fun.wmv'
},
{
filename:'jimmy.wmv'
},
{
filename:'herman.wmv'
}
],
folder:{
foldername:'videos',
file:[
{
filename:'abc.mp4'
},
{
filename:'june.mp4'
},
{
filename:'cleaver.mp4'
}
],
folder:{
foldername:'funny',
file:[
{
filename:'jelloman.wmv'
},
{
filename:'bellydance.flv'
}
]
}
}
}
}