Home > Article > Backend Development > A simple way to get the file extension in php_PHP Tutorial
This article mainly introduces the simple method of obtaining the file extension in php, and analyzes the techniques of obtaining the file extension in php with examples. Be sure to refer to the reference value. Friends who need it can refer to it
The example in this article describes how to simply obtain the file extension in PHP. Share it with everyone for your reference. The specific implementation method is as follows:
?
3 4 5
|
function get_file_extension($file_name)<🎜> <🎜>{<🎜> <🎜>/* may contain multiple dots */<🎜> <🎜>$string_parts = explode('.', $file_name);<🎜> <🎜>$extension = $string_parts[count($string_parts) - 1];<🎜> <🎜>$extension = strtolower($extension);<🎜> <🎜>return $extension;<🎜> <🎜>}<🎜> <🎜>$str="img.jpg";<🎜> <🎜>echo get_file_extension($str);//Output: jpg<🎜> <🎜>?> |