1

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.

Community
  • 1
  • 1

2 Answers2

0

I found a similar post here

  1. Make sure the database charset/coallition is UTF-8
  2. On the page you insert these russian characters ( the form, textarea ), make sure the encoding is UTF-8, by setting Content-Type to text/html; charset=utf-8. Enter in russian text directly to the form input.
  3. On the processing page that handles this form, which inserts it into the database, make sure to do SET NAMES utf8 so it's stored as UTF-8 before you insert the data, in a separate query beforehand.
  4. When you render the content from the database in a view, make sure the Content-Type is text/html; charset=utf-8.

Make sure that the content-type is not windows-1251 or iso-8859-1/latin1. Make sure the database charset/coallition is NOT ISO-8859-1/Latin1.

Community
  • 1
  • 1
Rémy Testa
  • 897
  • 1
  • 11
  • 24
0

Make sure your data is properly encoded as UTF8 — query it with an UTF8 capable terminal/application and confirm you can see the accented characters properly. If not, you'll need to check your input forms for properly setting the data encoding. Use <form accept-charset="utf-8"> but don't rely on it — check and convert if necessary at the backend.

Also make sure all your files are also encoded as UTF8: php files, templates, javascript, html widgets.

Capilé
  • 2,038
  • 17
  • 14