Home >Backend Development >PHP Tutorial >Five ways to get file name suffix in php

Five ways to get file name suffix in php

墨辰丷
墨辰丷Original
2018-06-13 10:01:282311browse

This article mainly introduces the common methods of obtaining file name suffix in PHP. It analyzes five common techniques of obtaining file name suffix in PHP. It has certain reference value. Friends in need can refer to it

The examples in this article summarize common methods for obtaining file name suffixes in PHP.

The specific implementation method is as follows:

<?php
header("Content-type:text/html;charset=utf-8");
$pic = "abc.jpg";
//第一种方法
$pics = explode(&#39;.&#39;,$pic);
$num = count($pics);
echo $pics[$num-1]."<br />";
//第二种方法
echo end($pics)."<br />";
//end()方法,获取数组最后一个单元值
//第三种方法
$info = pathinfo($pic);
echo $info[&#39;extension&#39;]."<br />";
//第四种方法
echo pathinfo($pic,PATHINFO_EXTENSION)."<br />";
//第五种方法
$offset = strrpos($pic,&#39;.&#39;);
//计算指定字符串在目标字符串中最后一次出现的位置
echo substr($pic,$offset+1);
?>

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's learning.

Related recommendations:

How to use array_key_exists and isset in php

php gets the index value of the array item with the largest key value in the array Method

php string splitting function method

The above is the detailed content of Five ways to get file name suffix in php. For more information, please follow other related articles on the PHP Chinese website!

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