How to remove an extension from a filename
Posted on September 4, 2008, 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!
- September 4, 2008
- article by Gabriel C.
- 1 comment
Related Posts
-
Get filename extensionat July 15, 2008 with 1 comment
-
PHP: Get filename of the currently executing scriptat May 21, 2008
-
How to Remove a (non-empty) Directory using PHPat September 28, 2008 with 1 comment
-
PHP: How to remove empty values from an arrayat May 21, 2008 with 10 comments
-
Format text into a SEO Friendly Stringat August 28, 2008 with 2 comments

One Reply to "How to remove an extension from a filename"
January 31, 2009 at 7:14 AM
hey
thanks man…
can u give any full source code…here it is just a function
…