PHP Excel reader2.21 Export Excel Chinese garbled solution explanation

Source: Internet
Author: User
Tags character set modify php file php excel php tutorial php web development variable xsl file

Before my PHP tutorial blog friends and relatives asked to use PHP Excel reader2.21 export Excel when the Chinese appear garbled how to solve, now I explain the next PHP Excel reader export Excel Chinese garbled solution, I hope to use PHP Excel Reader export Excel Friend is helpful.

  Introduction to PHP Excel reader

PHP Excel Reader is a PHP Excel class that reads the contents of an Excel XSL file, the latest version is the PHP Excel reader2.21, the website can search on its own, SourceForge PHP Excel Reader download Address I estimate is the initial version, this tutorial describes the PHP Excel reader export Excel Chinese garbled solution is based on PHP Excel reader2.21, so different versions of PHP to export Excel garbled solution is a difference, please be sure to download the correct version of PHP Excel reader.

  How to troubleshoot PHP Excel reader2.21 export Excel Chinese garbled?

After downloading the PHP Excel reader2.21, please unzip to the running directory of your PHP environment configuration, open example.php, First look

1
$data = new Spreadsheet_excel_reader ("Example.xls");

This statement is used to create an instance of PHP export Excel, where we can find the constructor prototype for this PHP Excel reader class in the excel_reader2.php file.

1
Spreadsheet_excel_reader ($file = ', $store _extended_info=true, $outputEncoding = ')

As the name suggests, PHP Excel reader export Excel file content encoding type is specified by the $outputencoding parameter, the default PHP Excel reader export Excel encoding type is through the variable _ Defaultencoding set, default for UTF-8, so usually solve PHP Excel reader export Excel Chinese garbled there are two ways.

  PHP Excel Reader Export Excel Chinese garbled solution one :

1
$data = new Spreadsheet_excel_reader ("Example.xls");

To

1
$data = new Spreadsheet_excel_reader ("Example.xls", True, "GB2312");

  PHP Excel Reader Export Excel Chinese garbled solution two : Open excel_reader2.php, find

1
var $_defaultencoding = "UTF-8";

Amended to

1
var $_defaultencoding = "GB2312";

Can solve the PHP Excel reader export Excel garbled problem.

Then why through the above tutorial changes, if you add Chinese after the Example.xls example.php still output garbled it? This is because it invokes the dump function in the PHP Excel reader class, which is used to export the contents of the exported Excel file as HTML, and the problem is precisely due to the htmlentities function in this function. The Htmlentities function is used to convert characters to HTML entities, as follows

1
Htmlentities (String,quotestyle,character-set)

Its default character set is Iso-8859-1, so when using the dump function of PHP Excel reader to export Excel with Chinese garbled characters,

  Workaround One :

1
$val = Htmlentities ($val);

Amended to

1
$val = Htmlentities ($val, Ent_compat, "GB2312");

  Workaround Two

1
$val = Htmlentities ($val);

Amended to

1
$val = Htmlspecialchars ($val);

  PHP Excel Reader Export Excel Chinese garbled solution summary

If you do not export Excel using the Dump function, you can either modify the _defaultencoding variable or pass the new Spreadsheet_excel_reader (Excel file name, true, Gb2312″); Solve the export Excel garbled problem, if you use the Dump function to export excel in HTML, you need to modify the Htmlentities function to solve the problem of exporting Excel garbled.

At this point, the use of PHP Excel reader2.21 export Excel Chinese garbled How to solve the introduction is over.

  Note : PHP Web Development Tutorials-leapsoul.cn Copyright, reproduced in the form of links to indicate the original source and this statement, thank you.







Related Article

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.