Showing posts with label file extension. Show all posts
Showing posts with label file extension. Show all posts

Thursday, February 7, 2013

Two different ways to find file extension in PHP


You can find a file extension in PHP using different ways.

Today I'll show you two different ways.

The first is a built-in PHP function called pathinfo(), which is used as follows:
$ext = pathinfo($filepath, PATHINFO_EXTENSION);
 Or by using some geeky PHP code as follows:
$path = '/path/to/img.gif';
$path = explode('.',$path);
$path = end($path);
That's It!
Sometimes, the key is in simplicity