PHP JSON - Exercises, Practice, Solution

PHP JSON [ 4 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]

1. Write a PHP script to decode a JSON string.
Click me to see the solution

2. Write a PHP script to decode large integers.
Sample integer :
{"number": 123456789012345678901234567890}
Click me to see the solution

3. Write a PHP script to get JSON representation of a value from an array.
Click me to see the solution

4. Write a PHP function to display JSON decode errors.
Click me to see the solution

PHP Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.

Follow us on Facebook and Twitter for latest update.

PHP: Tips of the Day

PHP: Pass a PHP string to a JavaScript variable (and escape newlines)

  var myvar = <?php echo json_encode($myVarValue); ?>;

Using json_encode() requires:

  • PHP 5.2.0 or greater
  • $myVarValue encoded as UTF-8 (or US-ASCII, of course)

Since UTF-8 supports full Unicode, it should be safe to convert on the fly.

Note that because json_encode escapes forward slashes, even a string that contains </script> will be escaped safely for printing with a script block.

Ref : https://bit.ly/34f0Dym


We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook