Jump to content

fgetcsv() function not recognising GBP - british pound character


samadams83

Recommended Posts

I am trying to get data from a CSV file using the fgetcsv function, but it seems to be ignoring the British pound character.

E.g. when i try and collect the data £500 from the file, it is returned as just 500.

I am attempting to use the function like this:

 

while ($row = fgetcsv($file_handle, 2000, $delimiter))
{
    //do something with the data
}

 

I also know the data is correct in the file itself, because this much clumsier version returns the right value:

 

while ($line = fgets($file_handle))
{
    $row = explode($delimiter, $line);
}

 

I would use this version, but it doesn't have the qualifier (e.g. double-quote) functionality i need.

 

Without using a large parsing function to get through the data, does anyone know how i can make fgetcsv() not strip out the £(pound) sign?

Thanks for that, very useful. Now all i need to do is understand that regex!

 

I also found another less universal solution: if an enclosure (e.g. ") is used on the data being read, the £ sign will show up correctly. Bug in PHP?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.