$data = (string)$data;
$encoding = mb_detect_encoding($data);
if($encoding == 'UTF-8') {
$data = preg_replace('/[^(\x20-\x7F)]*/','',$data);
$data = preg_replace('#\\\\x[0-9a-fA-F]{2,2}#','',$data);
}
$data = json_decode($data);
if (function_exists( 'json_last_error' )) {
switch (json_last_error()) {
case JSON_ERROR_NONE:
$this->log('validateJsonDecode() - No json decode errors');
break;
case JSON_ERROR_DEPTH:
$this->log('validateJsonDecode() - Maximum stack depth exceeded');
break;
case JSON_ERROR_STATE_MISMATCH:
$this->log('validateJsonDecode() - Underflow or the modes mismatch');
break;
case JSON_ERROR_CTRL_CHAR:
$this->log('validateJsonDecode() - Unexpected control character found');
break;
case JSON_ERROR_SYNTAX:
$this->log('validateJsonDecode() - Syntax error, malformed JSON');
break;
case JSON_ERROR_UTF8:
$this->log('validateJsonDecode() - Malformed UTF-8 characters, possibly incorrectly encoded');
break;
default:
$this->log('validateJsonDecode() - Unknown error');
break;
}
}else{
$this->log('validateJsonDecode() - json_last_error PHP function does not exist');
}
return $data;