Created
January 5, 2015 06:40
-
-
Save IftiMahmud/d39dbfa0e120a96c5b7d to your computer and use it in GitHub Desktop.
File Extension Finder in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Elegant Way to Find File Extension in PHP | |
// WAY-1: | |
$file_name = "ding.txt"; | |
echo substr(strrchr($file_name,'.'),1).'<br/>'; //Shows ext. eg; txt | |
echo substr(strrchr($file_name,'.'),0).'<br/>'; //Shows ext followed by a dot (.); eg; .txt | |
//WAY-2: | |
$file_name = pathinfo('/www/htdocs/inc/lib.inc.php'); | |
echo $file_name['dirname'].'<br/>'; | |
echo $file_name['basename'].'<br/>'; | |
echo $file_name['extension'].'<br/>'; | |
echo $file_name['filename'].'<br/>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment