0

I'm trying to save string to a file but we're getting a ? instead of the char. What would be the best way of being able to save chars like "È" to a file as a readable char. And also being able to html_decode($str) the string in php?

--UPDATE -----

adding "mysql:charset=utf8mb4;" to the PDO database connection fixed the problem.

-- STILL ENCOUNTERING PROBLEMS --

even though when I echo the string to the terminal now I can see it properly in the terminal. But once I save it to the file I get this:

CAF\u00c9

-- FILE SAVE EXAMPLE --

$jsonStr = '';

... process to query db and get string with utf-8 connection
and loop over all results and append a json_encoded string to each new line

loop start

    $jsonStr .= json_encode($array) . "\n";

loop end

file_put_contents($path, $jsonStr);

-- ANSWER --

json_encode needs the "JSON_UNESCAPED_UNICODE" flag as a second param

TheMan68
  • 1,429
  • 6
  • 26
  • 48

0 Answers0