How to convert special characters to normal characters?

半城伤御伤魂 提交于 2019-11-27 04:44:04

问题


I am trying to convert characters like:

ë, ä, ï, ö, etc.

To normal characters like:

e, a, i, o, etc.

What is the best way to do this? I've tried many things, like preg_replace and str_replace.

Can someone help me out?

-- EDIT --

What I tried, was:

$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);

回答1:


try this .. works for me.

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



回答2:


i like stewies' answer, but for completeness this works for me.

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


来源:https://stackoverflow.com/questions/9720665/how-to-convert-special-characters-to-normal-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!