» Birthday Bundle - Over $400 worth of Envato files for just $20

How to remove an extension from a filename

Posted on September 4, 2008, Filled under PHP,  Bookmark it

If you need for any reason to remove an extension from a filename (string) this snippet can help you. An extension in this case is everything after the last period from the whole string.

<?php
/*
Source: Bit Repository (http://www.bitrepository.com/)
*/
function remove_filename_extension($filename)
{
$extension = strrchr($filename, ".");

$filename = substr($filename, 0, -strlen($extension));

return $filename;
}

$filename = 'This-is-a-photo-description.jpeg';

$str = remove_filename_extension($filename);

echo $str;
?>

Do you wish to receive the latest updates as soon as they are posted? Get our RSS Feed or Subscribe to the Newsletter!

Get our RSS Feed!

Related Posts

One Reply to "How to remove an extension from a filename"

  1. hey

    thanks man…

    can u give any full source code…here it is just a function

Leave a Reply


* = required fields

  (will not be published)


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Note: If you want to post CODE Snippets, please make them postable first!
(e.g. <br /> should be converted to &lt;br /&gt;)