0

I have the following code:

/* change character set to utf8 */    
if (!mysqli_set_charset($con, "utf8")) 

{

printf("Error loading character set utf8: %s\n", mysqli_error($con));

} else {

printf("Current character set: %s\n", mysqli_character_set_name($con));

}

// query the application data
$sql = "SELECT * FROM names";

$result = mysqli_query($con, $sql);

// an array to save the application data
$rows = array();

// iterate to query result and add every rows into array
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) 
{

$rows[] = $row;
}


// close the database connection
mysqli_close($con);

// echo the application data in json format
echo json_encode($rows);

I try it on server http://blabla.gr/apps.php and I get \u0391\u03bd\u03c4\u03ce\u03bd\u03b7\u03c2 instead of Greek characters

How can i have them properly displayed as normal utf8 Greek characters.

1 Answers1

0

The json_encode function encodes Unicode characters using escape codes by default. You can use the JSON_UNESCAPED_UNICODE flag to leave them unescaped.

echo json_encode($rows, JSON_UNESCAPED_UNICODE);
Joni
  • 108,737
  • 14
  • 143
  • 193