如何将特殊字符转换为普通字符?

时间:2012-03-15 13:28:33

标签: php preg-replace special-characters

我正在尝试转换像:

这样的字符
ë, ä, ï, ö, etc.

正常人物如:

e, a, i, o, etc.

最好的方法是什么? 我尝试过很多东西,比如preg_replace和str_replace。

有人能帮助我吗?

- 编辑 -

我试过的是:

$ts = array("[À-Å]","Æ","Ç","[È-Ë]","/[Ì-Ï]/","/Ð/","/Ñ/","/[Ò-ÖØ]/","/×/","/[Ù-Ü]/","/[Ý-ß]/","/[à-å]/","/æ/","/ç/","/[è-ë]/","/[ì-ï]/","/ð/","/ñ/","/[ò-öø]/","/÷/","/[ù-ü]/","/[ý-ÿ]/");

$tn = array("A","AE","C","E","I","D","N","O","X","U","Y","a","ae","c","e","i","d","n","o","x","u","y");

$title = preg_replace($ts, $tn, $text);

3 个答案:

答案 0 :(得分:24)

试试这个..对我有用。

iconv('utf-8', 'ascii//TRANSLIT', $text);

答案 1 :(得分:18)

我喜欢stewies的答案,但为了完整性,这对我有用。

preg_replace("/&([a-z])[a-z]+;/i", "$1", htmlentities($foo));

答案 2 :(得分:0)

例如,它是根据内容标题创建一个简单的可读URL:

function cleanurl($title) {
        return urlencode(strtolower(str_replace(" ","-",preg_replace("/&([a-z])[a-z]+;/i", "$1", htmlentities($title)))));
}