Skip to content

Instantly share code, notes, and snippets.

@KATT
Created August 14, 2012 13:43
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save KATT/3349372 to your computer and use it in GitHub Desktop.
Save KATT/3349372 to your computer and use it in GitHub Desktop.
<?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