This article introduces the content loss and solutions when using iconv to encounter characters that cannot be transcoded when storing GBK data in a UTF8 encoded page. Students who have encountered such problems can refer to it.
About iconv interrupting and losing content when encountering characters that cannot be transcoded
The code is as follows
代码如下 |
复制代码 |
$c = ‘测试•字符传换•五一快乐!’;
echo iconv(‘utf-8′, ‘gbk’,$c);
|
|
Copy code
|
$c = ‘Test•Character transfer•Happy May Day! ’;
echo iconv(‘utf-8′, ‘gbk’,$c);
Only output: test
代码如下 |
复制代码 |
$c = ‘测试•字符传换•五一快乐!’;
echo iconv(‘utf-8′, ‘gbk//IGNORE’,$c);
|
The last one will be lost.
Solution:
Add //IGNORE |
The code is as follows |
Copy code |
$c = ‘Test•Character transfer•Happy May Day! ’;
echo iconv(‘utf-8′, ‘gbk//IGNORE’,$c);
Input and output: Test character transfer Happy May Day!
ignore means to ignore errors during conversion. Without the ignore parameter, all strings following this character cannot be saved.
This way you can do the same
http://www.bkjia.com/PHPjc/632140.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632140.htmlTechArticleThis article introduces the interrupt content when using iconv to store GBK data in UTF8 encoded pages when encountering characters that cannot be transcoded. The loss and solutions are available for reference by students who have encountered such problems. About iconv...
|