开发者

Best way to replace strings

I have an array where I'm storing the bad and good string pairs. Ex.:

array(
"Man. United"=>"Manchester United",
"Bay. Munchen"=>"Bayern Munchen",
"Bay. Mu开发者_JAVA百科nich"=>"Bayern Munchen",
...
) 

so in this case I'm using strtr to replace the given string, but in this case I always have to add or remove data's from the array. Is there any way to store just the good names in one array and replace which is very similar? For me is much easier to build up the array with the good names.


You could use similar_text or one of the other functions mentioned in the see also section to try and correct them automatically, but won't be as accurate as if you list the spelling mistakes yourself.

*edit: levenshtein may also be a good one to try...

The Levenshtein distance is defined as the minimal number of characters you have to replace, insert or delete to transform str1 into str2.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜