note 91434 modified in function.json-encode by danbrown

From: Date: Wed, 10 Jun 2009 12:39:54 +0000
Subject: note 91434 modified in function.json-encode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156738@lists.php.net to get a copy of this message
Be careful with floating values in some locales (e.g. russian) with comma (",") as decimal point. Code: <?php setlocale(LC_ALL, 'ru_RU.utf8'); $arr = array('element' => 12.34); echo json_encode( $arr ); ?> Output will be: -------------- {"element":12,34} -------------- Which is NOT a valid JSON markup. You should convert floating point variable to strings or set locale to something like "LC_NUMERIC, 'en_US.utf8'" before using json_encode. --was-- Be careful with floating values in some locales (e.g. russian) with comma (",") as decimal point. Code: -------------- setlocale(LC_ALL, 'ru_RU.utf8'); $arr = array('element' => 12.34); echo json_encode( $arr ); -------------- Output will be: -------------- {"element":12,34} -------------- Which is NOT a valid JSON markup. You should convert floating point variable to strings or set locale to something like "LC_NUMERIC, 'en_US.utf8'" before using json_encode. http://php.net/manual/en/function.json-encode.php

« previous php.notes (#156738) next »