[英]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.