There's a note in the
documentation that might be worth following up on.
Note: Locale setting is taken into account by this function. If LANG is e.g. en_US.UTF-8, files in one-byte encoding are read wrong by this function.
So what might be happening is that the pound sign is stored in the file as one byte, but fgetcsv is expecting the file to be encoded as utf8.
There really should be an argument to fgetcsv telling it what encoding to use, but there doesn't seem to be, so to control what encoding it uses, it looks like you have to change the global locale setting.
Code: Select all
// Assuming that the file is encoded as ISO_8859_1/Latin1
if(setlocale(LC_CTYPE, "en_UK.ISO88591")!="en_UK.ISO88591"){
die("couldn't set the required locale"); // just for testing
}
// now read in the csv file
I wouldn't be too happy about having to do this, as changing the locale affects the behaviour of all sorts of other things. If you have control of the csv file, it might be better to change its encoding to utf8, or just drop the pound sign, if it's always going to be a price in pounds in the nth column.