Getting file extension is not as easy as it looks. This is because there is no strict format for file extensions. Consider the following file names:
test.jpg
another image.jpeg
PHP Tutorial from Nashruddin.pdf
unusual.name.for.a.file.extension
my favorite, music.mp3
You cannot get the extension with substr($filename, -n), for example. To obtain the extension from filenames above, you have to use regular expression. See the following example.
Listing 1: get-fileext.php
Regular Expressions Cookbook
By: Jan Goyvaerts, Steven Levithan
This cookbook provides more than 100 recipes to help you crunch data and manipulate text with regular expressions. it offers step-by-step instructions for common tasks with Java, Perl, PHP, and many more.
Mastering Regular Expressions
By: Jeffrey Friedl
this book covers the basics of regular-expression syntax, and beyond. Written in an engaging style and sprinkled with solutions to complex real-world problems, it offers a wealth information that you can put to immediate use.
Jakub Neubauer on Sep 5, 2008:
Nash on Nov 9, 2008:
Elvita on Dec 15, 2008:
Nash on Dec 15, 2008:
Ning on Mar 31, 2009:
Nash on Mar 31, 2009:
Salman on Jun 29, 2009:
J on Jul 4, 2009:
carlo on Sep 13, 2009:
| Tel. | +62 31 8662872 +62 856 338 6017 |
| ICQ | 489571630 |
| Skype | dede_bl4ckheart |
| Yahoo | dede_bl4ckheart |
| nashruddin.amin |
Flashparry on Jul 27, 2008: