开发者

PHP - Parsing a string

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜