删除文件名的最后两位数字

时间:2013-11-02 01:16:31

标签: php string filenames

如何在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个字符与句点)。

1 个答案:

答案 0 :(得分:1)

如果你知道这个数字总是两位数,你可以使用负值作为substr_replace的开头:

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