Fri, 17 May 2024


How to remove the file extension from a file name using PHP?

By: Peter, NetArt Media
Sat, 6 June 2020

function RemoveExtension($strName)
{
$ext = strrchr($strName, '.');

if($ext !== false)
{
$strName = substr($strName, 0, -strlen($ext));
}
return $strName;
}

$Name = 'file.txt';

echo RemoveExtension($filename);


Category: PHP Examples
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox