I found great function to remove file extension from filename in PHP. Anton Zamov created this function and I’m just reporting it to show my appreciation.
Function:
function RemoveExtension($strName) { $ext = strrchr($strName, '.'); if($ext !== false) { $strName = substr($strName, 0, -strlen($ext)); } return $strName; }
Usage:
$filename = "myfile.jpeg"; echo RemoveExtension($filename);
Output:
myfile
Short, easy and understandable. If someone has a better solution let me know.
You can use the inbuilt pathinfo function to access the filename without extension
$filename= ‘woof.jpg’;
$string=pathinfo($filename,PATHINFO_FILENAME);
echo $filename;
// outputs woof