Remove last two digits of filename [closed]

巧了我就是萌 提交于 2019-12-08 15:27:43

问题


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

and

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

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


回答1:


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);


来源:https://stackoverflow.com/questions/19737927/remove-last-two-digits-of-filename

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!