Apologies if this is a silly question but I am learning at the minute and can not find the solution to this anywhere.
I have a name in my database table containing é. I run my sql query, pull down the data, put it into an array and then attempt to echo the json encode bur I get nothing. I can print_r and see the contents of the sql result, so I know the data has been sent from the database.
I've tried various things now including - json_encode($array, JSON_UNESCAPED_UNICODE). $ut= utf8_encode($contents); making sure the header = header('Content-Type: application/json; charset=utf-8', true,200);
When I use print_r where the é should be in the name I get a black diamond with a question mark in.
So basically I think I need to convert the é to unicode in order to echo the json encode?
Anyone any ideas?
Here is an example of the code I am using after running the sql.
$result = $conn->query($sql);
$data = array();
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
echo json_encode($data);
Maybe this will help someone in future.
I solved it by changing $data[] = $row; to $data[] = array_map("utf8_encode", $row);