开发者

MySql normalization of string

开发者 https://www.devze.com 2023-02-11 02:11 出处:网络
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_

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

精彩评论

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