PHP's json_encode does not escape all JSON control characters

后端 未结 12 1034
旧时难觅i
旧时难觅i 2020-11-28 12:08

Is there any reasons why PHP\'s json_encode function does not escape all JSON control characters in a string?

For example let\'s take a string which spans two rows a

12条回答
  •  悲哀的现实
    2020-11-28 12:23

    I still haven't figured out any solution without str_replace..

    Try this code.

    $json_encoded_string = json_encode(...);
    $json_encoded_string = str_replace("\r", '\r', $json_encoded_string);
    $json_encoded_string = str_replace("\n", '\n', $json_encoded_string);
    

    Hope that helps...

提交回复
热议问题