PHP and Web Technologies Freak
There are several methods get a file extension using PHP:
<? $filename = 'myfile.jpg'; // 1. The "explode/end" method $ext = end(explode('.', $filename)); // 2. The "strrchr" method $ext = substr(strrchr($filename, '.'), 1); // 3. The "strrpos" method $ext = substr($filename, strrpos($filename, '.') + 1); // 4. The "preg_replace" method $ext = preg_replace('/^.*\.([^.]+)$/D', '$1', $filename); // 5. The "never use this" method // From: http://php.about.com/od/finishedphp1/qt/file_ext_PHP.htm $exts = split("[/\\.]", $filename); $n = count($exts)-1; $ext = $exts[$n]; ?>
Copyright © 2007 - Ersin Acar - is proudly powered by WordPress
Dilectio Theme is created by: Design Disease brought to you by Smashingmagazine.com
Leave a reply