Remove file extension from filename in PHP

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.

Nikola Vasiljevski:
Related Post