How to get file extension in php?

This post, we helps you get file extension.

1. Code:

    <?php 	
    function getFileExtension($str) { 
     if ($str != null) { 
	 $array = array();
     $array = explode(".", $str);
	 $a = count($array);
	 return $array[$a -1];
     } 
     return ""; 
    } 
	$string = "soltuts.pdf";
	$string1 = "soltuts.csv";
     echo getFileExtension($string);
	 echo "<br>";
     echo getFileExtension($string1);
    ?> 

2. Example:

Input:

soltuts.pdf
soltuts.csv

Output:

pdf
csv