Fix Turkish Charset Issue HTML / PHP (iconv?)

I am having problems displaying Turkish characters, they appear as a small question mark with a diamond in the background in html.

How can I use iconv to fix this? So how do I think this is the best option? Now my page is encoded in utf-8.

I need to support characters like

ñ s

as well as the ability to insert them into my db.

thanks

+1
php character-encoding iconv turkish
source share
3 answers

Solved it using

iconv("ISO-8859-1", "UTF-8", $text); 
+4
source share

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

Then I recognized "iconv", tried and failed. Changed the locale with "setlocale". I tried Turkish, English and other types, failed.

Finally, I wrote this function and I am pleased 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); 
+7
source share

Although this is true in the general case, if the text $ contains some Turkish characters, such as ""ınar", the break will fail if your environment is not configured to work in Turkish.

If you may need to set the locale in php as shown below:

 setlocale(LC_ALL, 'tr_TR'); 
0
source share

All Articles