如何在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个字符与句点)。
答案 0 :(得分:1)
如果你知道这个数字总是两位数,你可以使用负值作为substr_replace
的开头:
$filename = 'filename11.jpg';
$newfilename = substr_replace($data, '', -6, 2);