Code: Select all
function split_dir_name ($dir)
{
$dir = explode ('/', ereg_replace ('//', '/', ereg_replace ('/$', '', $dir)));
for ($res = array (); empty ($res) || empty ($dir), $f = array_shift ($dir); $f == ".." ? array_pop ($res) : $res[] = $f);
return empty ($res) ? array ('.') : $res;
}

It takes a directory name something like this: 'pages/tutorials/php/' and gives you an array of the directory names back.
Thats not especially useful on its own (apart from doing breadcrumbs or something similar), but it also is quite handy, as it will work out the 'real' dir path when you give it things with ../ in for instance, so in goes:
'pages/tutorials/../downloads/wallpapers'
and out comes ['pages', 'downloads', 'wallpapers']
It also stops paths from going 'above' the cwd - so '../' would return '.', and it stops things like 'pages/../../' working too (so people can't nose around where they're not supposed to, if you're using a dir lister or something).