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

Garbled characters appear in the php import file

王林
王林Original
2019-10-18 09:41:492742browse

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");

Method two:

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

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

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');

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!

Statement:
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