如何删除重音符号并将字母变成“普通"字母? ASCII字符? [英] How to remove accents and turn letters into "plain" ASCII characters?
问题描述
从字符串中删除重音符号的最有效方法是什么,例如ÈâuÑ
变成Eaun
?
是否有一种简单的,内置的丢失或正则表达式的方式?
如果已安装iconv,请尝试以下操作(该示例假定您的输入字符串位于UTF-8中):
echo iconv('UTF-8', 'ASCII//TRANSLIT', $string);
(iconv是一个库,可以在各种编码之间进行转换;它是高效的,并且默认情况下包含在许多PHP发行版中.最重要的是,比起尝试使用自己的解决方案,它绝对更容易且更防错(您知道吗?是否存在带有卷曲的拉丁字母N"? >
What is the most efficient way to remove accents from a string e.g. ÈâuÑ
becomes Eaun
?
Is there a simple, built in way that I'm missing or a regular expression?
If you have iconv installed, try this (the example assumes your input string is in UTF-8):
echo iconv('UTF-8', 'ASCII//TRANSLIT', $string);
(iconv is a library to convert between all kinds of encodings; it's efficient and included with many PHP distributions by default. Most of all, it's definitely easier and more error-proof than trying to roll your own solution (did you know that there's a "Latin letter N with a curl"? Me neither.))
这篇关于如何删除重音符号并将字母变成“普通"字母? ASCII字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!