There is a site in Polish samopisny on SMARTY. Has been moved from one hosting to another. Now the site shows in places where there should be a Polish letter - question marks. Already the second day I sit over this problem

I forgot to clarify

The problem of the data that is taken from the database

On the first hosting

character_set_server = latin1 on a new character_set_server = latin2

I tried to add a file before the connections "require_once 'libs / Smarty.class.php';" as written in the documentation

if (function_exists('mb_internal_encoding')) { mb_internal_encoding('UTF-8'); } define('SMARTY_RESOURCE_CHAR_SET', 'UTF-8'); require_once 'libs/Smarty.class.php'; $smarty = new Smarty(); 

but there was no result from that. Of smarti did not work.

I will be grateful for the help.

  • And the problem with just html content or data from the database? - Telion
  • So your site may not be in UTF-8. - Visman
  • Did you configure the encoding of data from the database? mysqli_set_charset($link, "utf8"); - Telion
  • Visman, all .tpl is charset = utf-8 - klifort
  • Telion, no, I did not set it up, I didn’t work from the list - I don’t know how to create it, where to write this code - where does the connection to the database go? - klifort

2 answers 2

I have enough of these two lines for a multilingual website to work:

 <?php $host = 'localhost'; // адрес сервера $database = ''; // имя базы данных $user = 'root'; // имя пользователя $password = ''; // пароль $link = mysqli_connect($host, $user, $password, $database) or die("Error: " . mysqli_error($link)); mysqli_set_charset($link, "utf8"); mb_internal_encoding("UTF-8"); ?> 
  • Thanks helped, - klifort

It has nothing to do with Smarty at all (it is a template engine that only separates html from the code). If the situation arises only with data from the database, then first try to translate your database to UTF-8. Next, when connecting, specify the encoding:

 $link = mysqli_connect('localhost', 'my_user', 'my_password', 'test'); mysqli_set_charset($link, "utf8"); 

Also do not forget to specify this encoding in the page header.

PS Try not to use ACSII encoding (latin1, windows-1251). On modern projects, these are not the most convenient things (especially if you are using AJAX, WebSockets).

  • SET NAMES utf8; - this is the wrong approach! Read the comments php.net/manual/ru/mysqli.set-charset.php And the PDO encoding is specified in $ dsn. - Visman
  • @Visman corrected the answer - Dmitry Maslennikov