I've some problems with special characters in PHP/MySQL (I don't know which one).
Then, I've data stored in a database,using php. I ensured before storing data to add this code:
header('Content-type:text/html; charset=utf-8');
$link=mysqli_connect("host","user","","db") or die(mysqli_error($link));
mysqli_query($link,"SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8';SET NAMES utf8");
I also ensured Apache uses the correct charset:
AddDefaultCharset utf-8
In addition I also tried to add on every html page the meta
tag:
<meta http-equiv="content-type" content="text/html" charset="UTF-8">
Further, I saved all my php
and html
files in UTF-8
format.
I noticed that if I write a character like ò
in a page and display that page it is correctly displayed. If I get a string query from a database containing ò
, it doesn't display correctly, but if I change the code to:
header('Content-type:text/html; charset=iso-8859-1');
the query retrieved from the DB is correctly displayed, a normal writing not.
So,the problem is on mysql charset? How could it be if I setted it with the previous instructions?