fputcsv Encoding Issue

Discussion in 'PHP' started by adamjblakey, Jan 15, 2015.

  1. #1
    Hi All,

    I am having a problem with the code below. When i download the CSV files its putting a strange character in front of the £ symbol and i cannot figure why.

    $filename = "backup/download.csv";
    $handle = fopen($filename, 'w+');
    fprintf($handle, chr(0xEF).chr(0xBB).chr(0xBF));
    
    fputcsv($handle, array($row['sdate'], $row['red'], getcustomer($row['test']), $type."".$types, "£".$row['price'], "Save", $row['type']));
    
    Code (markup):

     
    adamjblakey, Jan 15, 2015 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Wrong character encoding? What character is it putting in front?
     
    PoPSiCLe, Jan 15, 2015 IP
  3. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #3
    Try doing utf8_decode("£") and see if that helps.
     
    ThePHPMaster, Jan 15, 2015 IP
  4. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #4
    That worked :) many thanks.
     
    adamjblakey, Jan 16, 2015 IP