How to remove diacritics from text?

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

    If you're just interested in making things URL safe, then you want urlencode.

    Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type. This differs from the » RFC 1738 encoding (see rawurlencode()) in that for historical reasons, spaces are encoded as plus (+) signs.

    If you really want to strip all non A-Z, a-z, 1-9 (what's wrong with 0, by the way?), then you want:

    $mynewstring = preg_replace('/[^A-Za-z1-9]/', '', $str);
    

提交回复
热议问题