PHP and Web Technologies Freak
This simple code example uses a combination of strrchr to find the last occurrence of a string and substr to return part of the string in order to find the file extension for a given filename. This is ideal if you want to quickly find a file extension.
$ext = substr(strrchr($fileName, '.'), 1);
This code can be used in the following way.
$fileName = '\path\to\file\afile.jpg'; $ext = substr(strrchr($fileName, '.'), 1); echo $ext;
The output here is ‘jpg’;
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