Json_encode with mysql content and umlauts in utf-8

I can feel my beard growing, trying to find a problem here.

The main problem is that Umlauts / Special Signs äöß ... do not work. I think everyone is tired of these issues, but all the solutions found on the Internet do not seem to work.

Im with utf-8 content in the Mysql utf-8 database. I feel that the problem exists somewhere in the database connection, but I just can't figure it out.

character_set_client utf8
character_set_connection utf8
character_set_database utf8
character_set_filesystem binary
character_set_results utf8
character_set_server latin1
character_set_system utf8

I'm not sure the problem is latin1 for character_set_server, because im is not included in this mysql stuff. I also do not know how to change the reason, I can not access the mysql server configuration files.

What bothers me is that if I get the results from the database and echo it, print_r gives the correct result.

ini_set('default_charset','utf-8'); header('Content-Type: text/plain; > charset=utf-8'); 

Firefox says char encode is utf-8, but if on exit i:

 print_r($listnew); echo json_encode($listnew[5]); 

print_r prints everything correctly, but json_encode does it wrong.

print_r:

 [5] => Array ( [id] => 5 [data] => U-Bahnhof Theresienstraße [size] => 17 ) 

json_encode:

{"id": 5, "data": "U-Bahnhof Theresienstra \ u00dfe", "size": 17}

I know that json_encode needs the utf-8 line to work correctly there, and I feel like I have a problem with the encoding here, but I just can't figure out where it is.

Any help would be appreciated

early.

i3

+4
source share
1 answer

Ummm ... I think this is the right way. \u00df is the correct unicode representation of ß . When you json_decode() , it will become ß again.

Where does this create problems for you? Does the receiving party really not decrypt it correctly? This is necessary if you use the standard json_* functions.

All examples from manual show the same thing - characters outside the ASCII range are converted to numeric sequences.

+5
source

Source: https://habr.com/ru/post/1309040/


All Articles