json_encode_safe
The PHP function json_encode_safe checks to see if current php version contains JSON functions.
If it does, then encodes the data. Otherwise it outputs an
error. Safe way to use json_encode because not all PHP setups
have JSON functions.
string $data - the data to encode
function json_encode_safe($data) {
// Package up the JSON
if(function_exists('json_encode')) {
return json_encode($data);
}
else {
return '{ "error": ["No JSON function in this version of PHP!"] }';
}
return;
}