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?

Link to comment
Share on other sites

$handle = fopen("mycsv.csv", "r");
while ($line = fgets($handle))
{
    $row = preg_split( "/[\s,]*\\\"([^\\\"]+)\\\"[\s,]*|[\s,]+/", $line, 0, PREG_SPLIT_DELIM_CAPTURE );
    print_r($row);
    print "<br>";
}
fclose($handle);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.