Character encoding on uploaded CSV file

Hi there.

I’ve a basic script used to upload a CSV file, which is then opened and the contents on the file is then displayed on a textarea, to be then manipulated using a series of Javascript tools. This all works fine, simply using move_uploaded_file() to handle the upload, and include() to show the contents of the file.

This all works fine, except that the data will always contain a few pound signs (£). When I save this CSV in Excel, and upload the file, the pound signs display as � - as far as I can tell, I can’t effectively change the encoding in Excel.

A possible work around is to open the file in a decent text editor, and change the encoding to UTF-8 and save. Then the upload all works perfectly and the pound signs are read ok. But I don’t want to have to rely on a user changing this encoding.

Any thoughts on a work around for this? If I open the incorrectly encoded file in a text editor, the pound signs DO display ok. Is there a way to re-encode the file on upload, or as it is displayed on the page?

Any help appreciated, thanks.

Ignore this above - I’ve solved it. Serious brain fart moment, having been staring at a screen too long…

Simply needed to change the way the file was outputted to display as a string, rather than an included file. I can then use utf8_encode() to work its magic.

Thanks for reading anyway :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service