Created
August 14, 2012 13:43
-
-
Save KATT/3349372 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Check if content is JSON | |
* | |
* @param string $content | |
* @return boolean | |
*/ | |
function w3_is_json($content) { | |
return json_decode($content) !== NULL; | |
} | |
/** | |
* Check if content is JSONP | |
* | |
* @param string $content | |
* @return boolean | |
*/ | |
function w3_is_jsonp($content) { | |
// Extract json | |
$stripped = preg_replace("/^\s*\w+\s*\(/", "", $content); | |
$stripped = preg_replace("/\)\s*$/", "", $stripped); | |
return w3_is_json($stripped); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment