04 - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of 04.php

  1. <?php
  2. function json_error_message($json_str)
  3. {
  4. $json[] = $json_str;
  5. echo $json;
  6. foreach ($json as $string)
  7. {
  8. echo 'Decoding: ' . $string."\n";
  9. json_decode($string);
  10.  
  11. switch (json_last_error())
  12. {
  13. case JSON_ERROR_NONE:
  14. echo ' - No errors'."\n";
  15. break;
  16. case JSON_ERROR_DEPTH:
  17. echo ' - Maximum stack depth exceeded'."\n";
  18. break;
  19. case JSON_ERROR_STATE_MISMATCH:
  20. echo ' - Underflow or the modes mismatch'."\n";
  21. break;
  22. case JSON_ERROR_CTRL_CHAR:
  23. echo ' - Unexpected control character found'."\n";
  24. break;
  25. case JSON_ERROR_SYNTAX:
  26. echo ' - Syntax error, malformed JSON'."\n";
  27. break;
  28. case JSON_ERROR_UTF8:
  29. echo ' - Malformed UTF-8 characters, possibly incorrectly encoded'."\n";
  30. break;
  31. default:
  32. echo ' - Unknown error'."\n";
  33. break;
  34. }
  35. }
  36. }
  37. json_error_message('{"color1": "Red Color"}');
  38. ?>
  39.  
File Description
  • 04
  • PHP Code
  • 25 Jan-2024
  • 777 Bytes
You can Share it: