Fix Turkish Charset Issue Html / PHP (iconv?)

夙愿已清 提交于 2019-12-29 09:25:09

问题


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 fix this? Since I think thats the best option right? Right now my page is utf-8 encoded.

I need to support characters like

ı ñ ş

aswell as be able to insert them into my db.

Thanks


回答1:


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);



回答2:


Solved it by using

iconv("ISO-8859-1", "UTF-8", $text);



回答3:


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');


来源:https://stackoverflow.com/questions/5122940/fix-turkish-charset-issue-html-php-iconv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!