开发者

PHP - Parsing a string

开发者 https://www.devze.com 2023-02-07 15:06 出处:网络
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 extensi

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消