if((index ($filename, $ext) + 1 + length($ext))==length($filename)){ #Extension was at end of $filename #Untested, I might be off by one }