How to remove extension from a file name using PHP

This code can be used to remove an extension from the file name using php.

If manipulated abit, it can also be used to find the extension of php and echo it.

function RemoveExtension($strName)
$ext = strrchr($strName, ‘.’);

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

$Name = ‘file.txt’;

echo RemoveExtension($filename);

However, in my case, i tried using it with a bunch of code but wasn’t successful, it did removed the extension of the file name but it caused the remaining code to stop executing. I didn’t work out on why it caused it as was busy in some more important part of that code.

hire best wordpress php css developer
Need Help? Hire me now!
I can help you in anything related to webdevelopment, including: HTML, CSS, PHP & MySql, WordPress (plugins & themes development, others), regular expressions, server management, etc.

Leave a Reply

Your email address will not be published.