Page 1 of 1

get a file name from a path.

Posted: Tue Sep 02, 2003 5:14 am
by yaron
Hi,
I have to write a function that takes the path and gets the file name
the path can come in this format:
'c:\\folderA\\folderB\\folderC\\folderZ\\file.txt'
Or in that format:
'c:/folderA/folderB/folderC/folderZ/file.txt'
Here is the script I use now:
preg_match('/([^\\\\]*(?!\\\\))$/', $path, $match);
$result = array_unique ($match);
print_r($result);
but it helps only for the first case. how can I write a small script that handle both?
Thanks

Posted: Tue Sep 02, 2003 5:55 am
by DuFF
I think the PHP function basename() will help you out a bit.

Posted: Tue Sep 02, 2003 6:32 am
by yaron
thanks
that is what i was missing