after using PHP to generate CVS files through Excel Open find Chinese all become garbled, before my local win08 through WPs Normal, but uploaded to server Linux on the server test has appeared garbledafter the start of the Linux problem but later found to be WPS problem (guess can be WPS to the code to do the processing, the server on the Excel Open is also garbled)
because my php files and the code in the database are in UTF-8 format and the code opened with a text editor is also UTF-8
PHP Codethe exported CVS document, opened with a text editor is no garbledusing Excel to open it is garbledMany people on the web say that the data in the database is converted from UTF-8 to GBKor you can specify the encoding in the header, both of which have been tried but are still useless
$html. = Iconv ("UTF-8", "GBK", $row [$key]). $tab; header ("content-type:text/html; Charset=utf-8 ")
So in this article it is found that as long as the BOM is added before the export of the document is resolved: PHP export CSV file with Excel Open appears garbled Chinese
However, because each row of the BOM after the cell is merged into one (\ t) but using table to solve the line-wrapping problem, but the unexpected discovery uses the table to solve the garbled problem (no BOM required)Workaround:
- The PHP file is encoded as UTF-8 and specifies that the header is encoded as
UTF-8 header ("Content-type:application/vnd.ms-excel;charset=utf-8");
- Database encoding set to UTF-8
- and use table to lay out ( add BOM before exporting the document)
Reference: PHP export Excel, Chinese garbled problem PHP export CSV file with Excel Open appears in Chinese garbled PHP generated CSV file when garbled to solve PHP export Excel garbled solution PHP export Excel (CSV) No garbled-perfect article PHP Chinese garbled solution
From for notes (Wiz)
Resolve PHP using CVS to export Excel garbled problem