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
Have you tried to use €
for € , instead of €
?
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);
Try this
//add BOM to fix UTF-8 in Excel
fputs($fp, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) ));
fputcsv($handler, $fields, ';', '"');
This was the only thing that cleanly fixed it for me
html_entity_decode($text, ENT_QUOTES, 'utf-8')
I don't know much in CSV files, but you should try these two things:
Put the euro symbol directly.
or
Look for the CSV file encoding.
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().