Fix Turkish Charset Issue Html / PHP (iconv?)

后端 未结 3 1128
情话喂你
情话喂你 2020-12-22 02:34

i\'m having troubles displaying turkish characters, they are appearing as the little question mark with the diamond in the background in html.

How can I use iconv to

相关标签:
3条回答
  • 2020-12-22 02:39

    First I tried, utf8 encode-decode, failed, changed file format from ASCII to UTF-8, tried utf encode again, changed file format several times and failed.

    Then i found out "iconv", tried and failed. Changed locale with "setlocale". Tried Turkish, English and other types, failed.

    At last i wrote this function and I'm happy with the output :)

    function transliterateTurkishChars($inputText) {
        $search  = array('ç', 'Ç', 'ğ', 'Ğ', 'ı', 'İ', 'ö', 'Ö', 'ş', 'Ş', 'ü', 'Ü');
        $replace = array('c', 'C', 'g', 'G', 'i', 'I', 'o', 'O', 's', 'S', 'u', 'U');
        $outputText=str_replace($search, $replace, $inputText);
        return $outputText;
    }
    $goodText=transliterateTurkishChars($badText);
    
    0 讨论(0)
  • 2020-12-22 02:45

    Solved it by using

    iconv("ISO-8859-1", "UTF-8", $text);
    
    0 讨论(0)
  • 2020-12-22 02:56

    Although that's true in general if $text contains some Turkish chars like "Çınar" translition will fail unless your environment is set to work on Turkish locale.

    In case you may need to set locale within php like below;

    setlocale(LC_ALL, 'tr_TR');
    
    0 讨论(0)
提交回复
热议问题