Returning Filename Only in PHP

How to strip file extension in PHP? I want to lose my filepath in my PHP string and then leave the filename without extension for the rest of it. I want to eliminate the darn extension! It’s very easy my friend. It’s basic, but it took me an hour to find the best solution. The solution is simple.

$yourString = "oh/my/god/this/is/my/file/path/AndThisIsMy.extension";
$myfilename = pathinfo($yourString, PATHINFO_FILENAME);
echo $myfilename; //it will return AndThisIsMy

PIECE of CAKE. Gimme that cake. I am so hungry.

Leave a Reply