Last active
September 25, 2019 15:23
-
-
Save lenivene/eff2adaa7c5c659254661c268fdce758 to your computer and use it in GitHub Desktop.
Check STRING is JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Check string is JSON | |
* | |
* @param string $json JSON to check | |
* | |
* @return boolean|array | |
*/ | |
function is_json( $json = null, $_return = false ){ | |
if( ! is_string( $json ) ){ | |
return false; | |
} | |
$_json = @ json_decode( $json, false ); | |
$is_json = $_json != null; | |
if( $_return !== true ) | |
return (bool) $is_json; | |
return ( $is_json ) ? $_json : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment