Get Filename without extension

Hello,

It's sometimes usefull to pick the name of the file without its extension, and this is very easy with php !

PHP Code:
<?php
$arr = explode(".", $allname);
$filename = $arr[0];

?>
But this script will not work the file name is dotted, in that case use this:

PHP Code:
<?php
$filename = preg_replace( '/\.[a-z0-9]+$/i' , '' , 'dotted.file.Name' );

?>
Or:

<?php
$FileNameTokens = explode('.', $allname);
$fileName = implode(".", array_slice($FileNameTokens, 0, count($FileNameTokens) - 1));

?>

If this is a few hard to understand, this script is easier:

PHP Code:
<?php
function getFilenameWithoutExt($filename){
$pos = strripos($filename, '.');
if($pos === false){
return $filename;
}else{
return substr($filename, 0, $pos);
}
}

?>

I hope this will help you.

1 comments:

Buy elo boost said...

oh yea, incredible. we sooo want to fulfill this person, he is an excellent create.

League of Legends elo boost


Buy Fifa 14 Ultimate Team Coins