0

I am trying to print a simple string in hebrew (UTF8) from mysql database. In the database the string is correctly, But when I print the string it's look like this - ×—× ×•×ª_חיות .

I would be happy if you can help me to understand why this is happened and how can I fix it. Thanks.

php -

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

mysqli_set_charset($conn,"utf8");

$sql = "SELECT * FROM Items WHERE id = '$token'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "," . $row["title"];
    }
} else {
    echo "Not found row";
}
mysqli_close($conn);
proli2
  • 1
  • 2
  • Review Mojibake in http://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James Aug 30 '16 at 00:39

1 Answers1

0

How does your HTML Document look like? Have you set UTF8 as character set? It should look like this:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>title</title>
    <link rel="stylesheet" href="style.css">
    <script src="script.js"></script>
  </head>
  <body>
    <?php

     //your php code 

     ?>
  </body>
</html>
Adam
  • 25,960
  • 22
  • 158
  • 247
  • Grate this is it, But unfortunately I can't use this because the other side (application) read this ass string and make some problems. Maybe there is another solution ? – proli2 Aug 29 '16 at 08:02
  • I have application that read this string. The problem is when I add the html stuff, It's add the html to the string and it's make problem to read this on the application side. – proli2 Aug 29 '16 at 08:30
  • And sorry it's as not ass ( ; – proli2 Aug 29 '16 at 08:31
  • @proli2 This sounds like you need to check in your application if `` was set in the header. Maybe there is a file called header.php that contains such a line? Another thing to check would be if your php file is actually saved as "UTF8 without BOM". You could save it in this type with notepad++. These are the only 2 things I can think of. – Adam Aug 29 '16 at 08:40