PHP utf-8 conversion gb2312 string truncated solution_PHP tutorial

WBOY
Release: 2016-07-13 10:54:21
Original
1216 people have browsed it

iconv (“utf-8”,“gb2312//ignore”,$data)
The direct meaning of ignore is to ignore, here it is to ignore errors during conversion. If there is no ignore parameter, all strings following this character cannot be saved.

conv is not the default function of the php tutorial, and it is also a module installed by default. It needs to be installed before it can be used.
If it is windows2000+php, you can modify the php.ini file and remove the ";" before extension=php_iconv.dll. At the same time, you need to copy the iconv.dll in your original php installation file to your winnt/system32


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

When using this function to convert string encoding, please note that if you convert utf-8 to gb2312, the string may be truncated.

You can use the following methods to solve this problem:

$str=iconv('utf-8',"gb2312//translit",file_get_contents($filepath));

That is, add the red part in the second parameter, which means: if no characters matching the source encoding are found in the target encoding, similar characters will be selected for conversion.


You can also use here: //ignore this parameter, which means to ignore characters that cannot be converted

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632331.htmlTechArticleiconv (utf-8,gb2312//ignore,$data) ignore directly means ignore, here it is Ignore errors during conversion. If there is no ignore parameter, all strings following this character cannot be saved...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!