dounie5475 2014-01-17 10:15
浏览 34
已采纳

用PHP标准化土耳其语?

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.

  • 写回答

1条回答 默认 最新

  • dtgj8529 2014-01-17 10:20
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?