I have this data to datatable cell: AlgoVital Plus čćš
so some characters is utf-8
Here's my database schema
After that I make json file with php and send it to fronted:
//header
header('Content-Type: text/html; charset=utf-8');
...
...
//at the end of php file:
$jsonTable = json_encode($table);
//echo $jsonTable;
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
echo $jsonTable;
and HTML head is OK too:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
but I cant show data with utf-8 characters... WHy?
JSON is not format with utf-8 characers... etc. where I have some characters like čćšž then I just get NULL at JSON file, when I use json encode
How I can solve this?
Try with this:
$table = utf8_encode($table);
$jsonTable = json_encode($table);
Try this
$table = '[{name: "PHP",version: 5.6}]'; //your json data
$jsonTable = json_encode($table, JSON_UNESCAPED_UNICODE);
$myObj = json_decode($jsonTable);
echo $myObj->name;