Created
December 5, 2013 02:13
-
-
Save fibbarth/7799095 to your computer and use it in GitHub Desktop.
Maneira de retornar somente o nome do arquivo sem usar função pathinfo. https://gist.github.com/ivanrosolen/7797439
This file contains hidden or 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 | |
$cases = array( | |
'/var/www/public/upload/image.jpeg', | |
'imagem.01.png', | |
'/ivan.pdf', | |
'/var/www/public/upload/imaginação.JPG', | |
'/var/www/nome bem legal.png', | |
'ilári iê.gif', | |
'/opa_ivan.01_03.jpeg', | |
'swp.ivan.01.12.2013.php', | |
'/var/www/_windows Like.gif', | |
'yudi.jPeG', | |
'.htaccess', | |
'/var/www/.htpasswd', | |
'/~teste.php' ); | |
foreach( $cases as $case ){ | |
echo 'PATHINFO:'.pathinfo($case, PATHINFO_FILENAME )."<br />"; | |
echo 'getFileName:'.getFileName( $case )."<br />"; | |
} | |
function getFileName( $string ){ | |
$filename = trim(array_pop(explode(DIRECTORY_SEPARATOR, $string)),'.'); | |
if( strpos($filename,'.') === false ){ | |
return $filename; | |
} | |
return substr($filename,0,strrpos($filename,'.')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment