开发者

MySql normalization of string

I'm using friendly_urls, and want to have an sqlfield 'friendly_url' which will depend on the field 'title'. So, if my title field is "This is My Title", my friendly_url field will be "this_is_my_title".

The problem is开发者_StackOverflow, while being a Portuguese website, the title field will often have characters like 'ç', 'ã', 'é', etc...

What is the best way (in mySql, if possible, in PHP if necessary), to turn "António Girão" to "antonio_girao"?

Thank you very much


You could be done in MySQL using triggers however I suppose it would be easier for you to do this using PHP. Here's Doctrine_Inflector::urlize() method that removes/replaces unwanted characters from string. You can use it.


A brute force method would be to use strtr to do in-place replacements:

strtr($string, "ÀÁÂÃÄÅàáâãäåā ", "aaaaaaaaaaaaa_")
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜