The php itself is having an inbuilt function to extract or get the file extension.No need to write any regular expression or a custom code to extract the file extension in PHP.the below example will give you the how to use the php code to extract or get the file extension quickly.This is fastest way to extract the file extension. basename() in built function to get the basename of the file or image.
* Author : Isaac Newton
$image_name = 'sample-logo.jpg';
$extension = pathinfo($image_name, PATHINFO_EXTENSION);
// it prints jpg
$new_image_name = rand().'.'.$extension;
// it prints some random number and concatinated with file extension