How to remove an extension from a filename
Posted on September 4, 2008, Filled under PHP,
Bookmark it
Thanks for visiting our website! We regularly publish posts like this one. If you are interested in receiving the latest updates as soon as they are posted, please consider subscribing to the RSS feed or to our e-mail newsletter.
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;
?>
