0

I need your help since I have a problem with accents and special characters. The thing is that I need to save an array in a database, so what I do is the following:

$serialized_array = json_encode($products, JSON_UNESCAPED_UNICODE);

The problem is that then when I retrieve this array from the database and do json_decode($serialized_array); it doesn't return anything.

Instead, if I do:

$serialized_array = json_encode($products);

Then when I do decode it returns the array but with the wrong tildes:

["Platos del d\u00eda","Plato - Los dos juntos"]

Database connection:

$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

mysqli_set_charset($link, "utf8mb4");

What can I do?

Thank you so much.

  • 1
    In what way are the accents wrong? can you post an example? One potential problem is that your database connection is not returning UTF-8 encoded text back to you. Can you include the database connection configuration int he question? Does this answer your question? https://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Joni Jul 08 '20 at 15:32
  • Just to be pedantic: "accent" represents the voice changes, and is not related to the drawings of the letters; those are "tildes". – The Impaler Jul 08 '20 at 15:50
  • 1
    1-For example: ["Platos del d\u00eda","Plato - Los dos juntos"] instead ["Platos del día","Plato - Los dos juntos"]. 2-And when encode with json_encode($products, JSON_UNESCAPED_UNICODE), the tildes are correct in bbdd but when I select this data I can´t decode it. 3-I try the solution of this question and the error continues. 4-Yes, I have included the database connection configuration. – IvannVerano Jul 08 '20 at 16:07
  • What is in `$products`? Show it both as a string and as hex. – Rick James Jul 09 '20 at 05:53
  • Hello, in $products there is strings, but the tildes are wrong. For example d\u00eda is the word día. – IvannVerano Jul 09 '20 at 07:47

0 Answers0