|
|
@@ -538,4 +538,25 @@ function file_get_contents_curl($url)
|
|
|
function getExtension($string)
|
|
|
{
|
|
|
return preg_replace("#(.+)?\.(\w+)(\?.+)?#", "$2", $string);
|
|
|
+}
|
|
|
+
|
|
|
+function safe_json_encode($value, $options = 0, $depth = 512)
|
|
|
+{
|
|
|
+ $encoded = json_encode($value, $options, $depth);
|
|
|
+ if ($encoded === false && $value && json_last_error() == JSON_ERROR_UTF8) {
|
|
|
+ $encoded = json_encode(utf8ize($value), $options, $depth);
|
|
|
+ }
|
|
|
+ return $encoded;
|
|
|
+}
|
|
|
+
|
|
|
+function utf8ize($mixed)
|
|
|
+{
|
|
|
+ if (is_array($mixed)) {
|
|
|
+ foreach ($mixed as $key => $value) {
|
|
|
+ $mixed[$key] = utf8ize($value);
|
|
|
+ }
|
|
|
+ } elseif (is_string($mixed)) {
|
|
|
+ return mb_convert_encoding($mixed, "UTF-8", "UTF-8");
|
|
|
+ }
|
|
|
+ return $mixed;
|
|
|
}
|