Escaping JSON apostrophe before PHP's json_encode truncates?

前端 未结 2 1531
后悔当初
后悔当初 2021-01-05 16:21

I have a field in a MySQL database (utf8_general_ci) that contains a curly (smart?) apostrophe: Owner’s...

This prints fine with no special handling if

2条回答
  •  萌比男神i
    2021-01-05 17:17

    Using PHP's utf8_encode() before my json_encode() did indeed stop the data from cutting off after the but it also encoded it to \0092 which did not display (control character). When I used MySQL's SET NAMES utf8 before my query, I did not have to use utf8_encode() at all, and my json was encoded correctly with mapping to \u2019, which displays nicely.

    Thanks for the link @Pekka, it helped me narrow down the possibilities.

提交回复
热议问题