Answer the question
In order to leave comments, you need to log in
How to fix encoding in PHP?
Hello!
I run the code below (displays a record from the database on the page), hieroglyphs appear.
Hosting nic.ru
Connection encoding mapping: utf8mb4_general_ci (phpmyadmin main page)
Encoding in the database table cp1251_general_ci
<?php
$host = 'myLogin.mysql';
$database = 'myLogin_test';
$user = 'myLogin_mysql';
$pswd = 'password';
$dbh = mysqli_connect ($host, $user, $pswd) or die ("No connect to server: " . mysql_error());
mysql_select_db ($database) or die ("No connect do db: " . mysql_error());
$query = "SELECT * FROM `my_sql_table`";
$res = mysql_query($query);
while($row = mysql_fetch_array($res))
{
echo "Номер: ".$row['id']."<br>\n";
echo "Имя: ".$row['firstname']."<br>\n";
echo "Фамилия: ".$row['surname']."<br><hr>\n";
}
?>
<html>
<head>
<title>Привет!</title>
<META charset='UTF-8'>
</head>
<body>Номер: 1<br>
РРјСЏ: E<br>
Фамилия: B<br>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
First you need to add to the html
head.
And don't forget that the file must be UTF-8 without BOM. The base encoding has nothing to do with it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question