How can I replace n and t with the corresponding carriage return and tab characters in front-end or php?

Source: Internet
Author: User
{Code...} I want to display formatted easy-to-read json strings on the front end
{"msg":"{\n \"iaback\" : {\n \"code\" : -3522,\n \"msg\" : \"\"\n },\n \"iawork\" : {\n \"code\" : 0,\n \"msg\" : \"---------------LibRxTx Info:--------------\\nCurrent peer:\\t4\\nWork Thread 0 235\\nWork Thread 1 255\\nWork Thread 2 247\\nWork Thread 3 244\\nEpLoop\\t\\t2513\\nEpRead\\t\\t1876\\nEpMoreRead\\t0\\nEpWrite\\t\\t895\\nSndLoop\\t\\t2183\\nPeerSnd\\t\\t1805\\nSndSw\\t\\t0\\nBufSnd\\t\\t908\\nAccept\\t\\t1778\\nPeerRcv\\t\\t1085\\nBufRcv\\t\\t1974\\nAddJob\\t\\t988\\nGetJob\\t\\t986\\nGetMore\\t\\t985\\nPktSnd\\t\\t888\\nPktRcv\\t\\t889\\nSndWait\\t\\t0\\nSndWaitAck\\t0\\n-------> Epoll 0\\nIdx ID RID State pktSnd ackRcv pktRcv pktExe ackSnd bw(Bps) Zip Retry\\tName\\n0 1 0 Lsn 0 0 0 0 0 -1 100 0\/-1\\t 127.0.0.1:26826 <--> :\\n1 2 0 Try 0 0 0 0 0 -1 100 96\/-1\\t :44115 <--> 192.168.17.9:26828\\n2 891 0 OK 0 0 1 0 0 -1 100 0\/-1\\tIPC 127.0.0.1:26826 <--> 127.0.0.1:57872\\n\"\n }\n}\n","result":0} 

I want to display formatted readable json strings on the front end

Reply content:
{"msg":"{\n \"iaback\" : {\n \"code\" : -3522,\n \"msg\" : \"\"\n },\n \"iawork\" : {\n \"code\" : 0,\n \"msg\" : \"---------------LibRxTx Info:--------------\\nCurrent peer:\\t4\\nWork Thread 0 235\\nWork Thread 1 255\\nWork Thread 2 247\\nWork Thread 3 244\\nEpLoop\\t\\t2513\\nEpRead\\t\\t1876\\nEpMoreRead\\t0\\nEpWrite\\t\\t895\\nSndLoop\\t\\t2183\\nPeerSnd\\t\\t1805\\nSndSw\\t\\t0\\nBufSnd\\t\\t908\\nAccept\\t\\t1778\\nPeerRcv\\t\\t1085\\nBufRcv\\t\\t1974\\nAddJob\\t\\t988\\nGetJob\\t\\t986\\nGetMore\\t\\t985\\nPktSnd\\t\\t888\\nPktRcv\\t\\t889\\nSndWait\\t\\t0\\nSndWaitAck\\t0\\n-------> Epoll 0\\nIdx ID RID State pktSnd ackRcv pktRcv pktExe ackSnd bw(Bps) Zip Retry\\tName\\n0 1 0 Lsn 0 0 0 0 0 -1 100 0\/-1\\t 127.0.0.1:26826 <--> :\\n1 2 0 Try 0 0 0 0 0 -1 100 96\/-1\\t :44115 <--> 192.168.17.9:26828\\n2 891 0 OK 0 0 1 0 0 -1 100 0\/-1\\tIPC 127.0.0.1:26826 <--> 127.0.0.1:57872\\n\"\n }\n}\n","result":0} 

I want to display formatted readable json strings on the front end

Do you want to display formatted JSON in a browser?
Var_export (json_decode ($ json_string); try this. You can format and save the object structure.
But if you show it in a browser, it is estimated that the above is not suitable, and it also prints the object information.
There are two ways to display only JSON formatted characters. if you use PHP 5.4 or earlier, you need to write the processing function by yourself.
This can be done directly after version 5.4:
Echo json_encode ($ arr, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT );
The result is formatted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.