public
Last active

  • Download Gist
define.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<?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);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.