green php elephants - elephpantsThere are plenty of methods of getting the file extension from a file name in PHP, but if you’re looking for a pretty quick and dirty way of achieving this without any hardcore validation, then it becomes a trivial matter of returning the bit of string after the last occurring . (fullstop) in the full file name string.

And given that PHP provides us with the handy strrchr function that finds the last occurrence of a character in a string, we can quickly whip up a file extension returning function that looks no more complex than this:

function get_file_name_extension($filenamestring) {
	return substr(strrchr($filenamestring,'.'),1);
}

Simple.