Home  >  Article  >  Backend Development  >  explode 的技巧

explode 的技巧

WBOY
WBOYOriginal
2016-06-20 12:35:11972browse

 比如我要取出   123.et.png     的最后一位   png

我可以这样子

 $file = '123.et.png';$str = explode(".",$file);echo $str['2'];


有什么方法,能直接获取explode分割后的最后一位
也就是说这个例子的话,就是直接获取  png  这个字段
因为$file这个字段长度是不固定的,其中的    ‘.’    也是不固定多少个

求助,有木有办法,直接获取explode分割后的最后一位


回复讨论(解决方案)

php 5.4 开始写做

echo explode(".",$file)[2];


但稳妥点应写作(假如不是两节呢)
echo array_pop(explode(".",$file));

正规的,应用 php 提供的函数 pathinfo

echo pathinfo('123.et.png', PATHINFO_EXTENSION);

正规的,应用 php 提供的函数 pathinfo

echo pathinfo('123.et.png', PATHINFO_EXTENSION);



这么隐蔽的函数。。。。真的是涨知识了。。
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