I would like to know how to parse the text of a file name so it keeps the extension.
so someimage.jp开发者_如何学Pythong
would become .jpg
. This is so I can change the file name but leave the extension.
Thanks.
Use pathinfo()
and pass the PATHINFO_EXTENSION
flag to get the file extension. You need to add the dot yourself as the function leaves it out:
$oldname = 'someimage.jpg';
$ext = pathinfo($oldname, PATHINFO_EXTENSION);
rename($oldname, 'thisimage.' . $ext);
精彩评论