-2

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

4

1 回答 1

1

substr_replace如果您知道该数字始终为两位数,则可以使用负值作为开始:

$filename = 'filename11.jpg';
$newfilename = substr_replace($data, '', -6, 2);
于 2013-11-02T01:22:12.073 回答