note 101293 added to function.json-encode
| From: | boukeversteegh at gmail dot com | Date: | Wed, 08 Dec 2010 15:58:14 +0000 |
| Subject: | note 101293 added to function.json-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174708@lists.php.net to get a copy of this message | ||
I discovered a rather bad bug in my __json_encode function below. On versions prior to php 5.2.5,
all 'f' characters are escaped to '\f'. This is because addcslashes in php <
5.2 doesn't understand \f as "formfeed". The fix is simple:
<?php
# Change this line:
$string = '"' . addcslashes($data, "\"\\\n\r\t\f/" . chr(8)) .
'"';
# Into this:
# I also put the \\ character first, as suggested in comments on the 'addclashes'
page.
$string = '"' . addcslashes($data, "\\\"\n\r\t/" . chr(8) .
chr(12)) . '"';
?>
----
Server IP: 213.249.64.162
Probable Submitter: 192.87.139.139
----
Manual Page -- http://www.php.net/manual/en/function.json-encode.php
Edit -- https://master.php.net/note/edit/101293
Del: integrated -- https://master.php.net/note/delete/101293/integrated
Del: useless -- https://master.php.net/note/delete/101293/useless
Del: bad code -- https://master.php.net/note/delete/101293/bad+code
Del: spam -- https://master.php.net/note/delete/101293/spam
Del: non-english -- https://master.php.net/note/delete/101293/non-english
Del: in docs -- https://master.php.net/note/delete/101293/in+docs
Del: other reasons-- https://master.php.net/note/delete/101293
Reject -- https://master.php.net/note/reject/101293
Search -- https://master.php.net/manage/user-notes.php