Escaping JSON apostrophe before PHP's json_encode truncates?

前端 未结 2 1519
后悔当初
后悔当初 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条回答
  • 2021-01-05 17:02

    For details: json_encode

    Example:

    echo json_encode($array, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题