A core feature of free hosting was a file manager that allows users to create, move and edit file/folder names. It was the necessary to take a long file path such as 'homefolder/subfolder1/subfolder2/subfolder3' and extract everything except for the basename.
- it's easy to get the basename of a path by just calling basename('stringOfFolder')
- calling basename('foldera/folderb/folderc') will return folderc
- however, there is no built in php function (at least at the time of writing this page) to get everything except for the basename of file/folder path. In other words, the purpose of this small php script is to extract foldera/folderb from a full path such as 'foldera/folderb/folderc'
Example in action
The actual PHP Code:
short name is a/b/
longName is a/b/c/d/e/f/
truncated name is c/d/e/f/
$shortName = 'a/b/' ;
"short name is $shortName" ;
$longName = $shortName . 'c/d/e/f/ ';
echo "longName is $longName" ;
//again strlen comes to our rescue
$truncatedName = substr($longName, (strlen($shortName)));
echo "truncated name is $truncatedName" ;