iconv UTF-8//IGNORE仍会产生“非法字符"错误 [英] iconv UTF-8//IGNORE still produces "illegal character" error

查看:746
本文介绍了iconv UTF-8//IGNORE仍会产生“非法字符"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$string = iconv("UTF-8", "UTF-8//IGNORE", $string);

我认为这段代码将删除无效的UTF-8字符,但是会产生[E_NOTICE] "iconv(): Detected an illegal character in input string".我缺少什么,如何正确地从非法字符中删除字符串?

I thought this code would remove invalid UTF-8 characters, but it produces [E_NOTICE] "iconv(): Detected an illegal character in input string". What am I missing, how do I properly strip a string from illegal characters?

推荐答案

输出字符集(第二个参数)应与输入字符集(第一个参数)不同.如果它们相同,则字符串中包含非法的UTF-8字符,根据输入的字符集,iconv将拒绝它们为非法.

The output character set (the second parameter) should be different from the input character set (first param). If they are the same, then if there are illegal UTF-8 characters in the string, iconv will reject them as being illegal according to the input character set.

这篇关于iconv UTF-8//IGNORE仍会产生“非法字符"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆