Home > Backend Development > PHP Tutorial > Issues you need to pay attention to when using iconv under PHP_PHP Tutorial

Issues you need to pay attention to when using iconv under PHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:33:23
Original
757 people have browsed it

string iconv ( string $in_charset , string $out_charset , string $str )

When using this function to convert string encoding, you need to pay attention. If you convert utf-8 When it is gb2312, the string may be truncated.

You can use the following method to solve this problem:

Copy the code The code is as follows:

//author: zhxia
$str=iconv('utf-8',"gb2312//TRANSLIT",file_get_contents($filepath));
That is, add the red part in the second parameter, which means: if If no character matching the source encoding is found in the target encoding, similar characters will be selected for conversion.

You can also use the //IGNORE parameter here to ignore characters that cannot be converted.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322644.htmlTechArticlestring iconv ( string $in_charset , string $out_charset , string $str ) Use this function to perform string encoding conversion When converting utf-8 to gb2312, it may be...
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