How to solve the garbled problem of php get

藏色散人
Release: 2023-03-14 14:20:01
Original
1801 people have browsed it

php get garbled solution: 1. Use the iconv function to convert the string according to the required character encoding; 2. Use mb_convert_encoding to convert the encoding.

How to solve the garbled problem of php get

The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

How to solve the garbled problem of php get? ?

The reasons and solutions for PHP receiving garbled Chinese parameters in GET

Option 1:

$str = iconv("gb2312","utf-8",$str);
Copy after login

Option 2:

mb_convert_encoding($str, "utf-8", "gb2312");
Copy after login

Related introduction:

iconv : Convert the string according to the required character encoding

Description

iconv(string $in_charset, string $out_charset, string $str): string
Copy after login

Convert the string str from in_charset to out_charset.

Parameters

in_charset
Copy after login

Input character set.

out_charset
Copy after login

Output character set.

If you add the string //TRANSLIT after out_charset, the transliteration function will be enabled. This means that when a character cannot be represented by the target character set, it can be approximated by one or more similar characters. If you add the string //IGNORE, characters that cannot be expressed in the target character set will be silently discarded. Otherwise, an E_NOTICE is caused and false is returned.

WARNING

//TRANSLIT operation details are highly dependent on the system's iconv() implementation (see ICONV_IMPL). It is reported that the implementation on some systems will directly ignore //TRANSLIT, so the conversion may fail and out_charset will be unqualified.

str

The string to be converted.

Return value

Returns the converted string, or returns false on failure.

php mb_convert_encoding: php built-in encoding conversion method.

Method prototype: string mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding = mb_internal_encoding() ] )

Convert the character encoding of string type str from optional from_encoding to to_encoding.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to solve the garbled problem of php get. 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