Home  >  Article  >  Backend Development  >  A simple way to get the file extension in php_PHP Tutorial

A simple way to get the file extension in php_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:00:36720browse

How to simply obtain the file extension in php

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:

?

1

2

3

4

5

6

7

8

9

10

11

12

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

?>

1 2

3

4 5

67 8 9 10 11 12
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<🎜> <🎜>?>
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/973123.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/973123.htmlTechArticleHow to simply obtain the file extension in php. This article mainly introduces the simple method of obtaining the file extension in php, with examples. Analyzes the technique of obtaining file extensions in PHP, which has certain reference value...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn