How to remove diacritics from text?

前端 未结 9 1660
余生分开走
余生分开走 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:23

    // normalize data (remove accent marks) using PHP's *intl* extension
    $data = normalizer_normalize($data);
    
    // replace everything NOT in the sets you specified with an underscore
    $data = preg_replace("#[^A-Za-z1-9]#","_", $data);
    

提交回复
热议问题