PHP Snippets
get_ext
Information
(PHP Version >= 3)Functions used in this snippet: substr, strrpos.
Description
str get_ext( str str[, bool ext] )
If ext is left as false, this function returns str with its file extension taken away.
If ext is set to true, only the extension is returned.
Snippet
<?php
function get_ext($str,$ext=false){
if($ext){
return substr($str,strrpos($str,'.')+1);
}
return substr($str,0,strrpos($str,'.'));
}
?>
Example
get_ext Can be used in the following way:
<?php
echo get_ext('somefile.php'); // somefile
echo get_ext('package.zip', true) // zip
?>
0 Responses to get_ext