本文介绍了删除文件名的后两位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在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);
这篇关于删除文件名的后两位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!