Home  >  Article  >  Backend Development  >  Summary of common methods for obtaining file name suffix in PHP, _PHP tutorial

Summary of common methods for obtaining file name suffix in PHP, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:06:19787browse

A summary of common methods for obtaining file name suffix in php,

The examples in this article summarize the common methods of obtaining file name suffix in PHP. Share it with everyone for your reference. The specific implementation method is as follows:

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

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/959881.htmlTechArticleA summary of common methods for obtaining file name suffixes in PHP. This article summarizes common methods for obtaining file name suffixes in PHP. Share it with everyone for your reference. The specific implementation method is as follows: phpheader("Co...
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