4

MySql database uses utf-8 encoding and data are stored correctly.I use set_name utf8 query to make sure the data called are utf-8 encoded.all variables from database works fine as long as the header charset is utf-8,but the static html characters do not work properly.When i set header charset to ISO-8859-9 variables are displayed differenly while html characters work ok.can anyone help me? Utf8 encoding: http://oi48.tinypic.com/289kje1.jpg html tags have problem displaying values.but php data(green ones e.g. ağişler) that come from database is ok.ISO encoding http://oi50.tinypic.com/287n2ph.jpg this time the html is ok but php data are displayed wrong.

<?php
    header('Content-Type: text/html; charset=ISO-8859-9');
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>noname</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Codette
  • 1,007
  • 2
  • 9
  • 18
  • So, is your content UTF-8 or ISO encoded? It can't be both. Save your source code in UTF-8! – deceze Nov 22 '12 at 17:01
  • i want it to be utf-8 encoded but turkish characters do not show up good in utf-8. for example Ş and İ are �� like that when don't include header charset ISO. – Codette Nov 22 '12 at 17:04

2 Answers2

11

You can try explicitly adding content type at the top of your file as below

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

and remove the below from your code..

header('Content-Type: text/html; charset=ISO-8859-9');

Update:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php echo "for example Ş and İ "; ?>   
</body>
</html>

The above code gives me the below output:

enter image description here

000
  • 3,976
  • 4
  • 25
  • 39
  • then the static characters are displayed wrong – Codette Nov 22 '12 at 17:03
  • show us how are they getting displayed and how would you like them to be with some example or screenshot.. – 000 Nov 22 '12 at 17:06
  • Utf8 encoding: http://oi48.tinypic.com/289kje1.jpg html tags have problem displaying values.but php data(green ones e.g. ağişler) that come from database is ok.ISO encoding http://oi50.tinypic.com/287n2ph.jpg this time the html is ok but php data are displayed wrong. – Codette Nov 22 '12 at 17:28
  • please find the update to my reply..and check if it solves the issue.. – 000 Nov 23 '12 at 16:34
  • well i made it work.the problem was solved after i used utf8-without bom option in my editor.and yours is the answer.thanks – Codette Dec 10 '12 at 20:52
1

So data from the database works if you tell the browser to interpret it as UTF-8, that means that data is UTF-8 encoded. The HTML code works if you tell the browser to interpret it as ISO-8859, that means the HTML is encoded in ISO-8859.

So you have a document with mixed encodings. Bring those two together. Save your source code files as UTF-8 and tell the browser to interpret it as UTF-8, or get your data from the database in ISO-8859 and tell the browser to interpret it thusly.

deceze
  • 510,633
  • 85
  • 743
  • 889