删除文件名的后两位 [英] Remove last two digits of filename

查看:85
本文介绍了删除文件名的后两位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在PHP中删除文件名的最后两个字符?

How can I remove the last two characters of a filename in PHP?

http://www.nws.noaa.gov/weather/images/fcicons/tsra50.jpg
# becomes
http://www.nws.noaa.gov/weather/images/fcicons/tsra.jpg

http://www.nws.noaa.gov/weather/images/fcicons/hi_shwrs60.jpg
# becomes
http://www.nws.noaa.gov/weather/images/fcicons/hi_shwrs.jpg

扩展名将始终为3个字符(带句点的4个字符).

The extension will always be 3 characters (4 with the period).

推荐答案

如果您知道数字始终为两位数,则可以使用负值作为substr_replace的开头.

You could use a negative value as start to substr_replace if you know that the number always is two digits:

$filename = 'filename11.jpg';
$newfilename = substr_replace($data, '', -6, 2);

这篇关于删除文件名的后两位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆