Home > Backend Development > PHP Tutorial > php获取文件名后缀常用方法小结_PHP

php获取文件名后缀常用方法小结_PHP

WBOY
Release: 2016-05-31 13:16:50
Original
1006 people have browsed it

本文实例汇总了php获取文件名后缀常用方法。分享给大家供大家参考。具体实现方法如下:

<&#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;>
Copy after login

希望本文所述对大家的php程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template