<?php $url = ' dir/upload.image.jpg '; function GetExt1 ($url) { return strrchr ($url, '. '); } function GetExt2 ($url) { return substr ($url, Strrpos ($url, '. ')); } function GetExt3 ($url) { $a = explode ('. ', $url); return Array_pop ($a); } function GetExt4 ($url) { $p = PathInfo ($url); return $p [' extension ']; } function GetExt5 ($url) { return Strrev (substr (Strrev ($url), 0, Strpos (Strrev ($url), '. '))); } $s = GETEXT5 ($url); Echo $s;? >
Note: 1, STRRCHR ()-function finds the last occurrence of a string in another string and returns all characters from that position to the end of the string. Otherwise, false is returned.
2, Array_pop (): Deletes the last element in the array. Return value: Returns the last value of the array. If the array is empty, or is not an array, NULL is returned.
3, PathInfo () returns an associative array containing information about path .
Includes the following array elements: [DirName], [basename], [extension]
PHP gets the file name extension