1

Hello forgive me for being new to this but I'm trying to output some unicode data from my php file.

The string that is suppose to be output is: "SD Tết Festival"

However I seem to be getting: "SD T\u1ebft Festival"

It's probably an easy overlook, but I cant figure it out.

I have searched and followed solutions here:

  1. How to take unicode characters from the mysql data base in PHP
  2. How to display Unicode data with PHP

PHP snippet code:

$sql = "select * from info";

mysqli_query($connection, "set character_set_client='utf8'");
mysqli_query($connection, "set character_set_results='utf8'");
mysqli_query($connection, "set collation_connection='utf8_general_ci'");

$result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection));

$rowCount = $result->num_rows;
$index = 1  ;
$newArray = [];
while($row =mysqli_fetch_assoc($result))
{   
    $newArray[$row['type']] = $row['content'];    
}

echo json_encode($newArray);

What do I seem to be doing wrong?

Thanks!

UPDATE:

I've added the following code as suggested by the solution in the duplicate question:

$connection->set_charset('utf8mb4');
mysqli_set_charset($connection, 'utf8mb4');

and removed:

mysqli_query($connection, "set character_set_client='utf8'");
mysqli_query($connection, "set character_set_results='utf8'");
mysqli_query($connection, "set collation_connection='utf8_general_ci'");

However, the output is still the same.

UPDATE 2: As suggested in the comment, I made sure the table and collation supports utf8mb4 as so:

enter image description here

enter image description here

I still seem to be getting the same output.

Community
  • 1
  • 1
Pangu
  • 3,721
  • 11
  • 53
  • 120
  • 1
    Possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – Charlotte Dunois Dec 02 '16 at 21:26
  • @CharlotteDunois: would appreciate the comment on my update..thanks – Pangu Dec 02 '16 at 22:01
  • 1
    The collation of the tables and field also have to be utf8mb4. Check if the data inside the table are not corrupt. – Charlotte Dunois Dec 02 '16 at 22:02
  • MySQL never generates `\u1ebf`; something else is generating that Unicode string. (And for that reason, I doubt if this is a dup of what Charlotte suggests.) – Rick James Dec 04 '16 at 00:58
  • Please do `SELECT col, HEX(col) FROM ...` just to determine whether the Unicode code was generated _before_ inserting, or during _ouput_. – Rick James Dec 04 '16 at 00:59
  • 2
    You're doing nothing wrong. `"SD T\u1ebft Festival"` is a valid way of encoding that string in JSON. A JSON parser (eg. `JSON.parse` in javascript) will turn that back into `SD Tết Festival`. – roeland Dec 05 '16 at 21:16

0 Answers0