0

When i try to insert polish character in Csv file .The polish character automatically turned to their respective htmlentities

<?php

header('Content-Type: text/csv; charset=UTF-8');   
header( 'Content-Disposition: attachment;filename=reports.csv');

echo ('åĄĆĘŁŃÓŚŹŻąćęłńóśźż');

?>
Output: å&#260;&#262;&#280;&#321;&#323;Ó&#346;&#377;&#379;&#261;&#263;&#281;&#322;&#324;ó&#347;&#378;&#380;

I need polish character to be displayed there.

Can anyone help me in order to solve this?

Thank you

Iam4fun
  • 1,438
  • 3
  • 14
  • 18

1 Answers1

0

Try this:

<?php

header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename=reports.csv');

$data = 'åĄĆĘŁŃÓŚŹŻąćęłńóśźż';

$csv_output = '="'.$data.'"'.chr(9).chr(13);

$csv_output = chr(255).chr(254).mb_convert_encoding($csv_output, 'UTF-16LE', 'UTF-8');

echo $csv_output;

?>

Also do not forget to save your php file as UTF-8 without BOM ...

chr(9) seprates fields and chr(13) separates rows ...

Night2
  • 1,168
  • 9
  • 18
  • ="åĄĆĘŁŃÓŚŹŻąćęłńóśźż" – Iam4fun Sep 18 '12 at 06:57
  • OK, I updated the answer again, it should work now 100% ... Test the new code again ... – Night2 Sep 18 '12 at 06:59
  • Are you sure that you have added my code update? `$csv_output = chr(255).chr(254).mb_convert_encoding($csv_output, 'UTF-16LE', 'UTF-8');` should be in your code, here is a file I created exactly with same code and it is working for me in my Excel 2010: http://encodable.com/uploaddemo/files/reports.csv – Night2 Sep 18 '12 at 07:17
  • Your php file should be UTF-8 without BOM, is it? (There are two UTF-8 files, one is with BOM, one is without BOM, a file with BOM can cause unwanted problems since it outputs something before your php code to browser) – Night2 Sep 18 '12 at 07:32
  • Hey thats really Great...It is working Awesome..Thanks for the precious time that you have spend for this..Thank you very much..GBU – Iam4fun Sep 18 '12 at 07:35