问题
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