Html entities like € is not converted to its symbol in CSV conversion

前端 未结 6 538
别跟我提以往
别跟我提以往 2021-01-19 16:13

I have used CSV parser from http://code.google.com/p/parsecsv-for-php/, to export my reports to CSV in PHP. I have displayed Sales Total value in €XXXX.XX

相关标签:
6条回答
  • 2021-01-19 16:17

    Have you tried to use € for € , instead of € ?

    0 讨论(0)
  • 2021-01-19 16:18

    You would need to use html_entity_decode() on the strings before writing them to file, which will find all html entities and replace them with their actual symbol.

    html_special_chars() and html_special_chars_decode() only works on a few html entities, like > and <, while htmlentities() and html_entity_decode() works on all of them.

    Alternatively, you could just do a string replace (str_replace() or preg_replace() or whatever) for € to replace with .

    Then Try:

    str_replace('€','€',$valuebeingexported);

    0 讨论(0)
  • 2021-01-19 16:24

    Try this

    //add BOM to fix UTF-8 in Excel
    fputs($fp, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) ));
    fputcsv($handler, $fields, ';', '"');
    
    0 讨论(0)
  • 2021-01-19 16:25

    This was the only thing that cleanly fixed it for me

     html_entity_decode($text, ENT_QUOTES, 'utf-8')
    
    0 讨论(0)
  • 2021-01-19 16:26

    I don't know much in CSV files, but you should try these two things:

    1. Put the euro symbol directly.

      or

    2. Look for the CSV file encoding.

    0 讨论(0)
  • 2021-01-19 16:40

    According to me Excel has some problems displaying CSV-files with unicode characters.You can try once below :

    use fputcsv() with utf-8 handling.

    something like below :

    $handler = fopen("php://output", "w");
    
    header("Content-Type: text/csv; charset=UTF-8");
    fputcsv($handler, $fields, ';', '"');
    
    fclose($handler);
    

    Note php://output is a write-only stream that allows you to write to the output buffer mechanism in the same way as print() and echo().

    0 讨论(0)
提交回复
热议问题