PHP: Remove File Extension
While writing a script to list the file in a specified folder on the server I wanted to remove file extension from the file name before I link it. Here is the php code that will remove the file extension.
< ? php
if(!function_exists("RemoveExtension"))
{
function RemoveExtension($strName)
{
$ext = strrchr($strName, '.');
if($ext !== false) {
$strName = substr($strName, 0, -strlen($ext));
}
return $strName;
}
}
? >
If you enjoyed this post, make sure you subscribe to my RSS feed!
Tags: file extension, php, php code, Programming, strlen, substr, writing a script

