There are many methods for getting the extension name of an object. Here is an introduction.
<? Php $ file_name = "bkjia.txt"; echo get_exname ($ file_name ); /*** get the file extension * @ param unknown_type $ file_name * @ return $ ex_name */function get_exname ($ file_name) {if (empty ($ file_name) return false; $ file_name = strtolower ($ file_name); $ rev_str = strrev ($ file_name); $ ex_name_len = strpos ($ rev_str ,'. '); // length of the extension $ file_name_len = strlen ($ file_name); $ ex_name = substr ($ file_name, $ file_name_len-$ ex_name_le N); return $ ex_name ;}?>
The strtolower () function converts a string to lowercase.
The strrev () function reverses the string.
The strpos () function returns the position where the string first appears in another string.
Find the position of the symbol '.' and calculate the length of the extension. Use the total length of the string minus the extension length to calculate the length to be truncated.