Echo Hebrew from mysql database to localhost
I have a mysql database and i'm using phpMyAdmin. I have a table contains
names in Hebrew (defined as VARCHAR and "uft8_general_ci") I tried to
fetch these names and print them as JSON array using the following php
code:
// array for JSON response
$response = array();
// include db connect class
include 'db_config.php';
// connecting to db
//$db = new DB_CONNECT();
$mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
/* change character set to utf8 */
if (!$mysqli->set_charset('utf8')) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
printf("Current character set: %s\n", $mysqli->character_set_name());
}
// get all contacts from contacts table
$result = $mysqli->query("SELECT * FROM myList");
// check for empty result
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$response[] = $row;
}
// echoing JSON response
echo json_encode($response);
} else {
// no contacts found
$response["success"] = 0;
$response["message"] = "No contacts found";
// echo no users JSON
echo json_encode($response);
}
The output I get in my localhost is:
[{"first_name":"\u05d0\u05de\u05d9\u05e8","last_name":"\u05de\u05d6\u05e8\u05d7\u05d9","phone":"516"},{"first_name":"\u05d0\u05d9\u05dc\u05df","last_name":"\u05de\u05d6\u05e8\u05d7\u05d9","phone":"490"},{"first_name":"\u05d0\u05d5\u05e8\u05d4","last_name":"\u05de\u05d6\u05e8\u05d7\u05d9","phone":"490"},{"first_name":"\u05d0\u05d9\u05d9\u05dc\u05d4","last_name":"\u05e4\u05d8\u05e8","phone":"636"},{"first_name":"\u05e2\u05d5\u05d6","last_name":"\u05e4\u05d8\u05e8","phone":"636"},{"first_name":"\u05d0\u05e1\u05e0\u05ea","last_name":"\u05d1\u05e8\u05d9","phone":"629"},{"first_name":"\u05e9\u05d5\u05e9\u05d9","last_name":"\u05d0\u05dc\u05de\u05e7\u05d9\u05d9\u05e1","phone":"554"},{"first_name":"\u05e9\u05dc\u05d5\u05dd","last_name":"\u05d0\u05dc\u05de\u05e7\u05d9\u05d9\u05e1","phone":"554"},{"first_name":"\u05de\u05e8\u05d9\u05dd","last_name":"\u05d1\u05e8\u05d9","phone":"491"},{"first_name":"\u05d9\u05d5\u05e1\u05d9","last_name":"\u05d1\u05e8\u05d9","phone":"491"}]
How can i fix it so i will be able to see Hebrew characters instead of
this unicoding?
Thanks!
No comments:
Post a Comment