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

icomxhvb  于 2023-02-21  发布在  PHP
关注(0)|答案(3)|浏览(120)

我正在尝试转换字符,如:

ë, ä, ï, ö, 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);
ztmd8pv5

ztmd8pv51#

试试这个...对我有用。

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

bnl4lu3b2#

我喜欢stewies的回答,但为了完整起见,这对我很有效。

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

nwlqm0z13#

例如,从内容标题创建一个简单可读URL:

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

相关问题