PHP Chinese encoding conversion problem

coldplay.xixi
Release: 2023-03-03 21:40:01
Original
2237 people have browsed it

php Chinese encoding conversion method: 1. Use the iconv function, the code is [string iconv (string $in_, string $out_, string $str)]; 2. Use the [mb_convert_encoding] function.

PHP Chinese encoding conversion problem

php Chinese encoding conversion method:

1. iconv

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

The first parameter: the original encoding of the content

The second parameter: the target encoding

The third parameter: the string to be converted

$filename='我爱你中国';
$filename = iconv('gbk','utf-8',$filename);
Copy after login

Analysis: Convert $filename from gbk to utf8

2. mb_convert_encoding

string mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding ] )
Copy after login

The first parameter: to be processed String

Second parameter: Target encoding

Third parameter: Original content encoding

$filename='我爱你中国';
$filename = mb_convert_encoding($filename,'GBK','UTF-8');
Copy after login

Analysis: Convert $filename from utf8 to gbk

三、mb_detect_encodingView character encoding

$filename='我爱你中国';
$encode = mb_detect_encoding($filename, array("ASCII","UTF-8","GB2312","GBK","BIG5"));
echo $encode;die;
Copy after login

Insert picture description here

PHP Chinese encoding conversion problem

Relevant learning recommendations: php programming (video)

The above is the detailed content of PHP Chinese encoding conversion problem. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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