note 101293 deleted from function.json-encode by danbrown

From: Date: Wed, 08 Dec 2010 16:04:13 +0000
Subject: note 101293 deleted from function.json-encode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-174710@lists.php.net to get a copy of this message
Note Submitter: boukeversteegh at gmail dot com Reason: integrated ---- 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)) . '"'; ?>

« previous php.notes (#174710) next »