/ Published in: PHP
A flexible way to get the file name without the extension
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* Detailed notes are below the code. */ $str_full_filename = 'tricky_filename_.js.jpg.version2.jpg'; $str_extension = $arr[ $int_last_element ]; echo 'The extension is '.$str_extension; echo '<br /> The file name (without the extension) is: '.$filename_without_extension; /* This is a group of methods to get the extension of a file or get a filename without the extension; this is especially useful when you need to copy an image (say filename.jpg), resize and rename to something like the following: 1. filename_small.jpg 2. filename_medium.jpg 3. filename_large.jpg I'm not covering how to resize images, just a way to copy the name and the extension so you can keep names consistent. The way I did this is to anticipate strange file names, so files with an extension name in it more than once won't cause errors or inconsistency. */