News Feed
Jobs Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Lorna Mitchell's Blog:
PHP Returning Numeric Values in JSON
July 12, 2011 @ 08:41:39

Lorna Mitchell has a quick reminder about an issue in the new joind.in API version - everything was being returned as strings, even integers.

A few weeks later (my inbox is a black hole and it takes a while to process these things) I fell over a throwaway comment to an undocumented constant JSON_NUMERIC_CHECK, and I added the constant name to my todo list. In the time it took for me to actually get around to googling for this, some wonderful person updated the PHP manual page (this is why I love PHP) to include it as a documented option, and someone else had added a user contributed note about using it.

This option, JSON_NUMERIC_CHECK, tells the json_encode function to property consider numbers in its encoding process. It applies globally, so if there's an instance where you don't want something assigned as a number, you might need to go with another, more flexible JSON encoding option. You can find information about this and other possible options json_encode can take on its manual page.

0 comments voice your opinion now!
jsonencode numeric integer string return encode jsonnumericcheck


blog comments powered by Disqus

Similar Posts

Lukas Smith's Blog: Lets talk about JSON in Symfony2

Joshua Thijssen: PHP5.5: Try/Catch/Finally

Chris Hartjes' Blog: Protecting Your PHP Code

Hasin Hayder's Blog: Counting occurrence of a word in a String - Benchmarking of PHP functions

DevShed: Developing a Captcha Application with an Image Generator Class with PHP 5


Community Events











Don't see your event here?
Let us know!


framework install component series language release symfony2 introduction podcast hack unittest hhvm performance application security composer package database opinion facebook

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework