Created
May 26, 2020 06:50
-
-
Save adamcrampton/babe38d635d989c623a8300a43321087 to your computer and use it in GitHub Desktop.
Determine if PHP string is valid JSON
This file contains 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 | |
/** | |
* Checks if string is valid JSON. | |
* | |
* @param string $string | |
* @return bool | |
*/ | |
public function jsonCheck($string) | |
{ | |
return json_decode($string, true) === null && json_last_error() !== JSON_ERROR_NONE ? false : true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment