Home >Backend Development >PHP Tutorial >A simple way to get the file extension in php, _PHP tutorial
The example in this article describes the simple method of obtaining the file extension in php. Share it with everyone for your reference. The specific implementation method is as follows:
<?php 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);//输出:jpg ?>
I hope this article will be helpful to everyone’s PHP programming design.