NeilWalden Posted June 3, 2013 Share Posted June 3, 2013 Hi, I'm using fgetcsv to read a csv file and cycle through it but I think the file is in a weird encoding. When I run strlen on any of the values it returns twice the length minus 1 that it should (e.g. for a string of length 5 it returns 9). Any ideas what it might be and how I can convert them to 'normal' encoding so I can do some string comparisons. I have tried truncating the strings with substr and can see that the extra length is per character rather than extra padding at the start end. Any help much appreciated it's been driving me crazy! Quote Link to comment https://forums.phpfreaks.com/topic/278710-werid-csv-encoding-strlen-returns-twice-length-it-should/ Share on other sites More sharing options...
DaveyK Posted June 3, 2013 Share Posted June 3, 2013 CSV is comma seperated right. Can you verify IN THE FILE that the commas are not the issue here ? Quote Link to comment https://forums.phpfreaks.com/topic/278710-werid-csv-encoding-strlen-returns-twice-length-it-should/#findComment-1433797 Share on other sites More sharing options...
kicken Posted June 3, 2013 Share Posted June 3, 2013 It's probably in an encoding such as UCS-2 which uses two bytes per character. You can use iconv or mb_convert_encoding to change it to a different encoding. Quote Link to comment https://forums.phpfreaks.com/topic/278710-werid-csv-encoding-strlen-returns-twice-length-it-should/#findComment-1433858 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.