php 如何将特殊字符转换为普通字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9720665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert special characters to normal characters?
提问by Mossawi
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.
做这个的最好方式是什么?我尝试了很多东西,比如 preg_replace 和 str_replace。
Can someone help me out?
有人可以帮我吗?
-- EDIT --
- 编辑 -
What I tried, was:
我试过的是:
$ts = array("[à-?]","?","?","[è-?]","/[ì-?]/","/D/","/?/","/[ò-??]/","/×/","/[ù-ü]/","/[Y-?]/","/[à-?]/","/?/","/?/","/[è-?]/","/[ì-?]/","/e/","/?/","/[ò-??]/","/÷/","/[ù-ü]/","/[y-?]/");
$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);
回答by Stewie
try this .. works for me.
试试这个……对我有用。
iconv('utf-8', 'ascii//TRANSLIT', $text);
回答by David Chan
i like stewies' answer, but for completeness this works for me.
我喜欢炖肉的回答,但为了完整起见,这对我有用。
preg_replace("/&([a-z])[a-z]+;/i", "", htmlentities($foo));