Extract filename with extension from filepath string

Dori picture Dori · Jun 30, 2010 · Viewed 24.9k times · Source

I am looking to get the filename from the end of a filepath string, say

$text = "bob/hello/myfile.zip";

I want to be able to obtain the file name, which I guess would involve getting everything after the last slash as a substring. Can anyone help me with how to do this is PHP? A simple function like:

$fileName = getFileName($text);

Answer

Daniel Egeberg picture Daniel Egeberg · Jun 30, 2010

Check out basename().