简体   繁体   English

iconv-注意:iconv()[function.iconv]:在输入字符串中检测到非法字符

[英]iconv - Notice: iconv() [function.iconv]: Detected an illegal character in input string

print iconv('UTF-8', 'us-ascii//TRANSLIT', 'Ин Совет Россия, дог фес ю!');

I don't get it why it throws this notice. 我不明白为什么它会发出此通知。 The string is a valid UTF8. 该字符串是有效的UTF8。

It should convert all characters to their ASCII equivalents, right? 它应该将所有字符都转换为等效的ASCII,对吗?

For example И should be I , н should be n and so on... 例如И应该是Iн应该是n ,依此类推...

The iconv function does not actually do transliteration; iconv函数实际上并不进行音译; the parameter name TRANSLIT is misleading. 参数名称TRANSLIT具有误导性。 The documentation says: “If you append the string //TRANSLIT to out_charset transliteration is activated. 文档说:“如果将字符串// TRANSLIT附加到out_charset,则音译会被激活。 This means that when a character can't be represented in the target charset, it can be approximated through one or several similarly looking characters.” Apparently this means just a set of ad hoc mappings, like “€” to “EUR”, and “ß” to “ss”. 这意味着当一个字符不能在目标字符集中表示时,可以通过一个或几个外观相似的字符对其进行近似。”显然,这意味着一组特定的映射,例如“€”到“ EUR”,以及“ß”到“ ss”。

For transliteration, you need something different. 对于音译,您需要一些不同的东西。 To transliterate Russian text from Cyrillic letters to Latin letters, the hard part is to decide which transliteration scheme to use. 要将俄语文本从西里尔字母音译为拉丁字母,困难的部分是决定使用哪种音译方案。 After that, it's just raw work. 在那之后,这只是原始工作。 Something like this, just with added data (arrays that cover the Cyrillic alphabet as used in Russian and the desired transliteration of each letter): 就是这样,只是添加了数据(覆盖俄语中使用西里尔字母的数组以及每个字母的期望音译):

$msg =  'Ин Совет Россия, дог фес ю!';
$cyr = array('и', 'я');
$lat = array('i', 'ya');
$latmsg = str_replace($cyr, $lat, $msg);
print $latmsg;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iconv():在输入字符串中检测到非法字符 - iconv(): Detected an illegal character in input string iconv在输入字符串中检测到非法字符 - iconv Detected an illegal character in input string iconv - 在输入字符串中检测到非法字符 - iconv - Detected an illegal character in input string 创建标题Slug时出错注意:iconv():在以下位置的输入字符串中检测到非法字符 - Error while Creating title Slug Notice: iconv(): Detected an illegal character in input string in 带有ascii的iconv //传输触发ErrorException:“ iconv():在输入字符串中检测到非法字符” - iconv with ascii // transit triggers ErrorException: “iconv(): Detected an illegal character in input string” iconv():在 FPDF 的输入字符串中检测到土耳其语字符的非法字符 - iconv(): Detected an illegal character in input string in FPDF for Turkish characters iconv():检测到输入字符串中不完整的多字节字符 - iconv(): Detected an incomplete multibyte character in input string 注意:iconv():在Excel_reader.php的输入字符串中检测到不完整的多字节字符 - Notice: iconv(): Detected an incomplete multibyte character in input string in Excel_reader.php 无法重现“iconv():在输入字符串中检测到非法字符”,但我一直在服务器上 - Can't reproduce “iconv(): Detected an illegal character in input string”, but I keep getting on server 使用iconv()检查无效的UTF-8字符:在输入字符串中检测到非法字符 - Using iconv() to check for invalid UTF-8 characters: Detected an illegal character in input string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM