0

Is there a way to simply normalize turkish characters like Ç, Ğ, İ, Ö, Ş, Ü and ı ?

cause now I'm using str_replace but that doesn't seem the right way to go, cause it's possible to forget a character.... Is there a more standard way? I tried to use the normalize method within the PHP internationalization module, but the Turkish characters stay Turkish. I would like to replace them with normal characters for the URL. So Ç becomes C and Ş becomes S, and so on.

Erik van de Ven
  • 4,747
  • 6
  • 38
  • 80

1 Answers1

1

What do you mean by normalization? Just take the characters as they come in, but put your scripts, connection and html in correct encoding.

UTF-8 suggested, explanation: UTF-8 vs. Unicode

If you only want ASCII chars, you can test this by something like ord($char) < 255.

For conversion look into these functions:

http://php.net/iconv

http://php.net/utf8_encode

http://php.net/mb_convert_encoding

A call similiar to

$str = iconv('UTF-8', 'ASCII//TRANSLIT', $str);

would do the trick.

Another preg_replace way: Convert special characters to normal characters using PHP, like ã, é, ç to a, e, c

Community
  • 1
  • 1
Daniel W.
  • 31,164
  • 13
  • 93
  • 151
  • 1
    Thank you for your complete answer! Iconv did the trick! I know it's kinda duplicate, but I really didn't want to use a str_replace or preg_replace with two manually filled arrays as told in http://stackoverflow.com/questions/4511194/convert-php-special-characters-like-a-a-a-e-c. That's why I asked it here again. But I'm glad there is an easier solution, iconv :) – Erik van de Ven Jan 17 '14 at 10:27