Skip to content

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 RemoveExtension($strName) {    $ext strrchr($strName, '.');    if($ext !== false) {       $strName substr($strName, 0, -strlen($ext));    }    return $strName; }


$filename = "myfile.jpeg"; echo RemoveExtension($filename);



Short, easy and understandable. If someone has a better solution let me know.

Posted in PHP.

Tagged with .

4 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Varun Nath says

    You can use the inbuilt pathinfo function to access the filename without extension

    $filename= ‘woof.jpg’;
    echo $filename;

    // outputs woof

  2. Nikola Vasiljevski Nikola Vasiljevski says

    Interesting, I have to try this out 🙂 Thanks!

  3. Ami says

    Thanks a lot! :))

  4. Anthony Armentrout says

    $filename= ‘woof.jpg’;
    echo $filename;

    // outputs woof

Some HTML is OK

or, reply to this post via trackback.