How to remove diacritics from text?

前端 未结 9 1680
余生分开走
余生分开走 2020-11-29 04:56

I am making a swedish website, and swedish letters are å, ä, and ö.

I need to make a string entered by a user to become url-safe with PHP.

Basically, need to

9条回答
  •  鱼传尺愫
    2020-11-29 05:16

    as simple as

     $str = str_replace(array('å', 'ä', 'ö'), array('a', 'a', 'o'), $str); 
     $str = preg_replace('/[^a-z0-9]+/', '_', strtolower($str));
    

    assuming you use the same encoding for your data and your code.

提交回复
热议问题