


How to solve the problem of garbled characters in Excel when read by PHP
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.
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; }
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’);
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!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool