Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

php - How to convert special characters to normal characters?

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("[à-?]","?","?","[è-?]","/[ì-?]/","/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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

try this .. works for me.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...