mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-23 13:59:29 +00:00
Fix old content encoding issue
This commit is contained in:
parent
edf7f88e98
commit
5ac5f17eac
35
3rdparty/RestServer/RestServer.php
vendored
35
3rdparty/RestServer/RestServer.php
vendored
@ -34,6 +34,33 @@ use ReflectionObject;
|
||||
use ReflectionMethod;
|
||||
use DOMDocument;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////// THESE FUNCTIONS FIXE ENCODING ISSUES DUE TO PREVIOUS ENCODING ///////
|
||||
/////////// CHOICES ////////////////////////////////////////////////////////////
|
||||
//////////// THEY HAVE NOT BEEN TESTED ENOUGH, USE WITH CAUTION !!!!! //////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
function do_fix_utf8($input){
|
||||
if(\json_encode($input) == FALSE)
|
||||
return utf8_encode($input);
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
function check_utf8($input) {
|
||||
|
||||
if(is_array($input)) {
|
||||
$out = array();
|
||||
foreach($input as $key => $value)
|
||||
$out[$key] = check_utf8($value);
|
||||
return $out;
|
||||
}
|
||||
else
|
||||
return mb_detect_encoding($input) == "UTF-8" ? do_fix_utf8($input) : $input;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Description of RestServer
|
||||
*
|
||||
@ -432,7 +459,13 @@ class RestServer
|
||||
$options = JSON_PRETTY_PRINT;
|
||||
}
|
||||
$options = $options | JSON_UNESCAPED_UNICODE;
|
||||
echo json_encode($data, $options);
|
||||
|
||||
// Return data
|
||||
$output = json_encode($data, $options);
|
||||
if($output === FALSE)
|
||||
$output = json_encode(check_utf8($data), $options);
|
||||
echo $output;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user