Resolve PHP using CVS to export Excel garbled problem

Source: Internet
Author: User

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:
    1. 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");
    2. Database encoding set to UTF-8
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.