Skip to content

Instantly share code, notes, and snippets.

@minwe
Forked from KATT/define.php
Created June 10, 2014 05:36
Show Gist options
  • Save minwe/6dddb980b603f4d21509 to your computer and use it in GitHub Desktop.
Save minwe/6dddb980b603f4d21509 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