Posted By

mladoux on 01/03/12


Tagged

json


Versions (?)

is_json


 / Published in: PHP
 

URL: http://markladoux.com

function to test whether or not a string is JSON encoded

  1. /**
  2.  * is_json
  3.  *
  4.  * determines whether or not a string contains valid json encoding.
  5.  *
  6.  * @param string $string string to test
  7.  * @return bool true if valid, false if not
  8.  */
  9.  
  10. function is_json($string) {
  11. return is_array(json_decode($string));
  12. }

Report this snippet  

You need to login to post a comment.