After json_encode, "\ n" becomes "\\ n".

json_encode"\n""\\n"
 : \n
:\\n
json_encode  320
JSON_UNESCAPED_SLASHES 64 + JSON_UNESCAPED_UNICODE  256

 \\n
Php
May.31,2022

depends on whether you want to use \ n as a newline character or an ordinary string, define it with "" as a newline character, and use '' as an ordinary string.

In

JSON format data, \ n is the newline character
"I love learning\ n" , \ n is the newline character
'I love learning\ n', \ n is an ordinary string

therefore, the ordinary string \ n should be escaped when it becomes JSON data to avoid being treated as a newline

.

// 
echo json_encode('[\n]').PHP_EOL; //  "[\\n]"
echo json_encode("[\n]").PHP_EOL; //  "[\n]"
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b321ae-2bde0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b321ae-2bde0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?