note 96105 deleted from function.json-encode by danbrown
| From: | danbrown@php.net | Date: | Tue, 09 Feb 2010 14:09:09 +0000 |
| Subject: | note 96105 deleted from function.json-encode by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-165799@lists.php.net to get a copy of this message | ||
Note Submitter: antti at neocard dot fi
----
adding to Andys array_to_json,
if the output is processed with eval the linefeeds break the eval.
You need to escape the linefeeds with
} else if( !is_numeric( $value ) || is_string( $value ) ){
$value = "'".addslashes($value)."'";
}
to
} else if( !is_numeric( $value ) || is_string( $value ) ){
$value = "'".addslashes($value)."'";
$value = str_replace( "\n", "\\n", $value ); // linefeeds break eval
}