I would like to know how to parse the text of a file name so it keeps the extension.
so someimage.jpg would become .jpg. This is so I can change the file name but leave the extension.
Thanks.
I would like to know how to parse the text of a file name so it keeps the extension.
so someimage.jpg 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);