search
HomeBackend DevelopmentPHP ProblemWhat to do if php explode Chinese garbled characters

What to do if php explode Chinese garbled characters

May 26, 2021 pm 06:01 PM
explodephpChinese garbled

Solution: 1. In the php.ini configuration file, find and set the value of the "defalut_charset" item to "utf-8"; 2. In the php program, use "@ini_set(' default_charest','utf-8');" statement can set the encoding method.

What to do if php explode Chinese garbled characters

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In PHP, use explode to split A Chinese string, for example, when using explode(':','fileName:filename'), the returned "filename" will be garbled. How to solve this? Let me introduce to you the solution below.

php explode Chinese garbled solution:

1. Configure the php.ini file

Settingsdefalut_charset = 'utf-8' ;

What encoding is used by the program? Just fill in the corresponding encoding here

2. Use ini_set()

If you cannot change php.ini, then You can use

@ini_set('default_charest','utf-8');

in a php program to achieve the same effect.

Description:

ini_set - Set the value for a configuration option. The syntax is as follows:

ini_set ( string $varname , string $newvalue )

Set the value of the specified configuration option. This option will retain its new value while the script is running, and will be restored when the script ends.

Parameters

  • varname: Not all valid options can be changed using ini_set(). There is an appendix with a list of valid options.

  • newvalue: The new value of the option.

Return value

  • Returns the old value on success, returns false on failure.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if php explode Chinese garbled characters. 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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT

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.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.