简体   繁体   English

以ASCII转换UTF-8重音

[英]Convert UTF-8 accents in ASCII

I saw there are different discussion on this subject and I did find some solutions, but I still can't fix the accent problem. 我看到有关于此主题的不同讨论,并且确实找到了一些解决方案,但是我仍然无法解决重音问题。

I have a text in Italian, we have some letters with accents ( à , è , é , ì , ò and ù ), this text gets sent in a file over to another website and this has to be in ASCII format, this is what I'm currently doing: 我有一个意大利语文本,我们有一些带有重音符号( àèéìòù )的字母,这些文本以文件形式发送到另一个网站,并且必须为ASCII格式,这就是我目前正在做:

$res_to_write = "Non c'è più l'oblò, è lì o là?" //DEMO TEXT
$resfile = iconv("UTF-8", "US-ASCII//TRANSLIT", $res_to_write);

The result is in ASCII, which is good but it gets converted to: 结果以ASCII表示,这很好,但是将其转换为:

Non c'e piu l'oblo, e li o la?

Which is completely wrong in Italian. 这在意大利语中是完全错误的。

Do I have to make a replace of every accent like è => e' (single quote) so at least looks ok or there is another solution to this? 我是否必须替换每个重音符号,例如è => e' (单引号),以便至少看起来还可以,或者对此有其他解决方案?

As of now I don't have other solutions other than replace it with an apostrophe: 到目前为止,除了用撇号代替它之外,我没有其他解决方案:

$res_to_write = "Non c'è più l'oblò, è lì o là?" //DEMO TEXT
$res_to_write = str_replace(['à', "è", "é", "ì", "ò", "ù"], ["a'", "e'", "e'", "i", "o'", "u'"], $res_to_write);
$resfile = iconv("UTF-8", "US-ASCII//TRANSLIT", $res_to_write);

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM