Amit Dhamu

Writes Code

Get File Extension

Method 1

$file = 'video.mp4';
$extension = preg_replace('/^.*./', '', $file);


Method 2

$file = "video.mp4";
$extension = explode(".", $file);
$extension = end($extension);


Method 3

$file = "video.mp4";
$extension = explode(".", $file);
$extension = array_pop($extension);


Method 4

$file = "video.mp4";
$extension = pathinfo($file, PATHINFO_EXTENSION);


Method 5

$file = "video.mp4";
$file_info = pathinfo($file);
$extension = $file_info["extension"];

// $file_info is an Array which will output something similar to:
Array
(
    [dirname] => .
    [basename] => video.mp4
    [extension] => mp4
    [filename] => video
)


Method 6

$file = 'video.mp4';
$extension = substr(strrchr($file,"."), 1);


file / extension / regex / regular expression / php

← Available List Style Types Get Mouse Coordinates →