PHP Function To Get A File Extension From A String

Getting the file extension from a PHP string can be very important in validating a file or file upload. I’ve written a simple PHP function to retrieve a file extension from a string. The Code function get_file_extension($file_name) { return substr(strrchr($file_name,’.’),1); } This simple method of file extension retrieval should be reused throughout your code.