Question marks (not symbols) are displayed instead of Cyrillic

  • UTF-8 file encoding without BOM
  • Utf-8 is specified in .htaccess
  • MySQL is fully translated to utf8mb4_general_ci (in the database itself, the Cyrillic is adequately displayed)
  • Encoding in <head> is correct

Php itself:

<?php $connect = mysqli_connect("localhost", "", "", ""); mysql_query('SET NAMES "utf8"'); $output = ''; if(isset($_POST["query"])) { $search = mysqli_real_escape_string($connect, $_POST["query"]); $query = " SELECT * FROM post WHERE title LIKE '%".$search."%' "; } else { $query = " SELECT * FROM post ORDER BY test "; } $result = mysqli_query($connect, $query); if(mysqli_num_rows($result) > 0) { $output .= ' <div class="table-responsive"> <table class="table table bordered"> <tr> <th>Customer Name</th> <th>Address</th> <th>City</th> <th>Postal Code</th> <th>Country</th> </tr> '; while($row = mysqli_fetch_array($result)) { $output .= ' <tr> <td>'.$row["title"].'</td> <td>'.$row["test"].'</td> <td>'.$row["City"].'</td> <td>'.$row["PostalCode"].'</td> <td>'.$row["Country"].'</td> </tr> '; } echo $output; } else { echo 'Data Not Found'; } ?> 

Maybe someone faced with a similar? I suffer all day.

  • Check whether the browser sees the correct indication of the encoding =) try to manually specify the browser encoding. If the file is indeed in the correct encoding, output the test message from the Cyrillic (echo 'Check!';) - Vladimir Klykov

1 answer 1

In addition to the first line, you can try to add two more (so that you are 100% sure):

 mysql_query("SET NAMES 'utf8'"); mysql_query("SET CHARACTER SET 'utf8'"); mysql_query("SET SESSION collation_connection = 'utf8_general_ci'"); 

And yet .. the text fields of the tables in the database should be in utf8_general_ci coding, most likely this is the problem (after changing the coding of the tables, they will most likely have to be refilled, since there will be broken data)

  • It didn't lead to anything - noobsaibot
  • @noobsaibot hmm, you can find out exactly what is specified in the head, in htaccess? And also check if all the database tables and all text fields are specified with the encoding utf8mb4_general_ci - Alex Zaharchuk
  • @noobsaibot in general seems to me the main problem is not the correct encoding in the database, wrote in the response more - Alex Zaharchuk
  • <meta http-equiv = "Content-Type" content = "text / html; charset = utf-8"> and AddDefaultCharset utf-8 in .htaccess under Apache. All text fields have utf8mb4_general_ci encoding (they have even created a separate table in this database) - noobsaibot
  • @noobsaibot should be utf8_general_ci (not mb4) - Alex Zaharchuk