Saturday, August 24, 2019
php - json_encode() doesn't display arabic characters in good way
Answer
Answer
i have problem with Arabic characters when i do json_encode() it always return ????, in the database all the fields and database is utf8
my code:
$query = mysql_query("SELECT * FROM `Names`");
if (!$query) {
$message = 'Invalid query: ' . mysql_error() . "\n";
die($message);
}else
{
while ($row = mysql_fetch_assoc($query))
{
$result[] = array(
'Mid' => $row['Mid'],
'Uid' => $row['Uid'],
'Cid' => $row['Cid'],
'Name' => $row['Name'],
'city' => $row['city'],
'status' => $row['status'],
'Mobile' => $row['Mobile'],
'Phone' => $row['Phone'],
'Email' => $row['Email']);
}
header('Content-Type: application/json; charset=utf-8');
echo json_encode($result);
}
the result look like:
[{"Mid":"17","Uid":"1","Cid":"8","Name":"???? ?? ??????? ?? ???","city":"?????",
please help me
Answer
Try this before sending your query
mysql_query("SET NAMES 'utf8'");
or this (if your PHP version is 5.4.0 or above)
json_encode($result, JSON_UNESCAPED_UNICODE);
Note: In case that your data are stored in hex format, enclose json_encode
with mysql_escape_string()
.
Subscribe to:
Post Comments (Atom)
hard drive - Leaving bad sectors in unformatted partition?
Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...
-
Using Windows 7. When I RDP to a PC I'd like to be able to logout of the session without the screen reverting to a Ctrl+Alt+Del Login sc...
-
I tried adding grubx64.efi in the Windows Boot Manager using BCDEdit. However when I boot up my computer and try to start GRUB from Windows ...
-
So I installed Ubuntu Netbook Remix 9.10 onto my Asus EeePC 1008HA netbook. It worked perfectly and was pretty quick. Restarting, suspending...
No comments:
Post a Comment