Home > Backend Development > PHP Tutorial > The role of PHP encoding conversion in Excel reading_PHP tutorial

The role of PHP encoding conversion in Excel reading_PHP tutorial

WBOY
Release: 2016-07-15 13:33:17
Original
940 people have browsed it

PHP has developed a lot. Now pear is very convenient to use. There are related classes to read the contents of Excel files. If you don’t want to use pear If so, you can consider using excel_class.php. If you google it, you can find the source code of this class to download, and you can also find the basic example code, which is very convenient to use.

What you need to pay attention to when converting PHP encoding is that what is read from Excel belongs to UTF-16LE encoding. If you use excel_class in mobile applications, you need to pay attention because mobile phones usually support UTF-8. Coding, which involves the conversion of codes.

For example, I use

echo $return[Sheet2][0][0];

to display the content in row 1 and column 1. The original content is " Start", it is indeed "Start" when displayed on the web using PHP, but the source code of viewing the web page is

开始

where is for displaying on the web page It shows that the hexadecimal representation of 24320 and 22987 is the "start" UTF-16LE encoding.

Then what we need to do is convert this UTF-16LE encoding to UTF-8 encoding.
First open excel_class.php, find the function uc2html, comment out the code in the function, and return the parameters directly, that is, changing the function does not perform any operation.

function uc2html($str) {
return $str;
}

Next, use the function mb_convert_encoding provided in PHP to convert UTF-16LE to UTF-8.

echo mb_convert_encoding($return[Sheet2][0][0], 'UTF-8', 'UTF-16LE');

At this point, UTF-16LE is completed UTF-8 PHP encoding conversion.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446088.htmlTechArticlePHP has developed a lot. Now pear is very convenient to use, and there are related classes to read Excel files. For the content inside, if you don’t want to use pear, you can consider using excel_class.php,...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template