I am basically after a method of extracting a file name from a path. The file type may change and the file name may have white space in it. Also the path may be in Unix form or Windows form.
/Users/Bob/Documents/some file.docx
Or
C:\Users\Bob\My Documents\some file.docx
The complete source path is already stored in a variable called $fileSource and I have the file name without the extension in a variable called $fileName. I have tried to use str_replaceto replace the common part of the file source with zero space but the path may change so this is not viable.
I thought if regex could be used to work backward through the string the last (reading from left to right) \ or / but I don't really know much regex yet. I have read about a look-backward feature which should start (?<=string) but I can't get this to work.
Lastly The reason I need the file name with the extension is because I am using PHP to copy it from one location to another and if I don't have the file extension the files turns up without the extension and I have to add it manually.
If what I am asking is not possible I guess I could just use regex to get the file extension and then concatenate that to the $fileName but I am hoping for something more graceful.
Cheers.
pathinfo.basename($fileSource)work? If not, why not?