BigToach.com

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
?>

Added on Jul 6th at 5 am by Scott - 0 Comments


0 Responses to get_ext

Name:

Site or Mail:

Comment:

To try to reduce the ammount of spam, please enter the word GOOSE in the following form

Security Code: