note 100272 added to function.json-encode
| From: | tomas at matfyz dot cz | Date: | Tue, 05 Oct 2010 14:43:34 +0000 |
| Subject: | note 100272 added to function.json-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172972@lists.php.net to get a copy of this message | ||
As json_encode() won't work with character sets other than UTF-8, this expression allows to
encode strings for JSON regardless of the character set:
str_replace("\0", "\\u0000", addcslashes($string, "\t\r\n\"\\"));
You need to replace the nul character manually as addcslashes() won't do it right way. But
BEWARE, this is only solution for common strings, other "unusual wild characters" like
ESC, \b, \a etc. are not handled.
----
Server IP: 147.32.160.17
Probable Submitter: 213.220.235.37
----
Manual Page -- http://www.php.net/manual/en/function.json-encode.php
Edit -- https://master.php.net/note/edit/100272
Del: integrated -- https://master.php.net/note/delete/100272/integrated
Del: useless -- https://master.php.net/note/delete/100272/useless
Del: bad code -- https://master.php.net/note/delete/100272/bad+code
Del: spam -- https://master.php.net/note/delete/100272/spam
Del: non-english -- https://master.php.net/note/delete/100272/non-english
Del: in docs -- https://master.php.net/note/delete/100272/in+docs
Del: other reasons-- https://master.php.net/note/delete/100272
Reject -- https://master.php.net/note/reject/100272
Search -- https://master.php.net/manage/user-notes.php