You can try something like this:
<?php $file = 'a.cool.picture.jpg'; $ext = substr($file, strrpos($file, '.')+1, strlen($file)-strrpos($file, '.')); $name = substr($file, 0, strrpos($file, '.')); echo $name.'.'.$ext; ?>
The key functions are strrpos (), which finds the last occurrence of a character (in this case ".") And substr (), which returns a substring. You find the last "." in the file, and sub is the string. Hope this helps.
source share