Get file extension with PHP

Free Scripts :: PHP :: Files and Folders :: Get file extension with PHP

Author: Salman Javaid

Website: http://www.salman.be

  • How to get file extension with PHP.
  • Custom PHP function to get file extension.

Function accepts a string parameter which is the name of complete file name. It returns the extension against supplied file name.

Function

function getExtension($string){
    $i = strrpos($string,'.');
    if (!$i) {
        return '';
    }
    $l = strlen($string) - $i;
    $extension = substr($string,$i+1,$l);
    return $extension;
}

Calling The Function

echo getExtension('image.jpg');

Output

.jpg

Comments

No comments. Be the first one.

Leave a comment

Full Name*
Comments*
Security Code*

Our Partners

Getty Icons  Salman Creations
Free High Quality Images  Learn Free Languages 
Opal Hosting  R-Tech Solutions
  • Submit a Script

    Click here to submit your script.