Skip to content

Instantly share code, notes, and snippets.

@fibbarth
Created December 5, 2013 02:13
Show Gist options
  • Save fibbarth/7799095 to your computer and use it in GitHub Desktop.
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
<?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