sst['data'][ $ind])"; 2. Comment out the "uc2html" function."> How to solve the problem of garbled characters in Excel when read by PHP-PHP Problem-php.cn

How to solve the problem of garbled characters in Excel when read by PHP

藏色散人
Release: 2023-03-05 18:30:01
Original
3502 people have browsed it

Solution to the problem of php reading excel garbled characters: 1. Modify the "excel_class.php" class file to "$s=iconv('utf-16le','utf-8′,$exc-> sst['data'][$ind])"; 2. Comment out the "uc2html" function.

How to solve the problem of garbled characters in Excel when read by PHP

Recommended: "PHP Video Tutorial"

php reads excel Chinese garbled excel_class...

Today I encountered a big problem, which is the big problem of reading Chinese garbled characters in Excel!

Excel_class.php is a tool for php to import excel. It can easily import data from excel to php, and can also use php to import data into excel. But today it is very ineffective!

I collected a lot of information but couldn’t find it. Then I thought: Baidu is our best teacher. Okay, let’s go find the teacher now!

Sure enough, I searched on Baidu about how to deal with garbled characters using this tool.

The first method: modify the excel_class.php class file, find $s = uc2html($exc->sst['data'][$ind]); and replace it with $ s = iconv('utf-16le','utf-8′,$exc->sst['data'][$ind]), so the encoding is utf-8.

If you still want Import the data into mysql, and your mysql encoding is GB2312, then you need to transfer the data from utf-8 to gb2312. You can do this: $s=iconv(“UTF-8″,”GB2312″,$s ).

Second method: 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 without doing any operation.

function uc2html($str) { return $str; }
Copy after login

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’);
Copy after login

The display will be normal.

Summary: During my test, it was recommended to use the first method. The second method turned the numbers into garbled characters (I don’t know why).

The above is the detailed content of How to solve the problem of garbled characters in Excel when read by PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!