phpstringpathfilenamesstring-parsing

Get filename from a filepath string


How can I get Application6.docx from a string like files/abcd/Application6.docx?

In simple words I am just trying to get the file name along with its extension Application6.docx.

Note: files/abcd/ can be different ppt/file/ so I cannot use the trick of replacing files/abcd/.


Solution

  • You can use basename to get what you want.

    $file = basename("files/abcd/Application6.docx");