I am supposed to create website for customer with content in Slovak language (that means it contains special characters
like č, č, ó, ď, ť and so).I'm using MySQL database with data encoding utf8_general_ci
. This data is fetched by PHP
which generates HTML code and fills it with this textual data recieved from database. I used:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
in head of generated HTML,
modified php.ini using steps mentioned here,
in php script itself called header('Content-Type: text/html; charset=utf-8')
. Result is that all special characters are
displayed like questionmarks.
Is there any finite list of steps to do to secure that everything will be displayed properly?
EDIT:
As I found solution already, I would like to share steps that helped me to handle UTF-8 website, if anybody struggles too.
1.) Change php.ini using steps mentioned in this article's best answer.
2.) In the beginning of responsible php script call header('Content-Type: text/html; charset=utf-8');
.
3.) Before executing any query, call mysqli_query($con,"SET NAMES utf8");
(I call it once on the top of the script right after setting up $con
connection).
4.) Place <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
in head of your HTML code.
5.) Change your database's collation to any utf8 type (I use utf8_general_ci
as I mentioned).
Hope it helps.