Home > Backend Development > PHP Problem > Garbled characters appear in the php import file

Garbled characters appear in the php import file

王林
Release: 2023-02-27 08:52:01
Original
2972 people have browsed it

Garbled characters appear in the php import file

Question 1:

When writing code on Windows, the test encountered a garbled code problem.

Method one:

Use the function mb_convert_encoding() and make the following settings:

$str = mb_convert_encoding($str, "UTF-8", "GBK");
Copy after login

Method two:

Use the function iconv() and make the following settings:

iconv(‘GBK',”UTF-8//TRANSLIT//IGNORE”,$str);
Copy after login

These two functions are used to solve the problem of garbled characters on Windows.

Question 2: When

was submitted to the Linux system, garbled characters occurred again.

php reads csv files, but Chinese cannot be read on Linux. Solution:

Add a line of code:

setlocale(LC_ALL, 'zh_CN');
Copy after login

PHP setlocale( ) Function explanation:

setlocale() function sets regional information (regional information).

Regional information is language, currency, time and other information for a geographical area. This function returns the current locale, or false on failure.

Recommended tutorial: PHP video tutorial

The above is the detailed content of Garbled characters appear in the php import file. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template