Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions php/utility/json.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class JSON
{
public static function safeEncode($value)
{
$encoded = json_encode($value);
return(!function_exists('json_last_error') || json_last_error()==JSON_ERROR_NONE ? $encoded : json_encode(UTF::utf8ize($value)));
return json_encode($value, JSON_THROW_ON_ERROR|JSON_INVALID_UTF8_SUBSTITUTE);
}
}
}
55 changes: 0 additions & 55 deletions php/utility/utf.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,61 +107,6 @@ public static function win2utf($str)
return($outstr);
}

private static function mix2utf($str, $inv = '_')
{
$len = strlen($str);
for($i = 0; $i < $len; $i++)
{
$c = ord($str[$i]);
if($c > 128)
{
$bytes = 0;
if(($c > 247)) $str[$i] = $inv;
elseif($c > 239) $bytes = 4;
elseif($c > 223) $bytes = 3;
elseif($c > 191) $bytes = 2;
else $str[$i] = $inv;
if($bytes)
{
if(($i + $bytes) > $len) $str[$i] = $inv;
else
{
$start = $i;
$cnt = $bytes;
while($bytes > 1)
{
$i++;
$b = ord($str[$i]);
if($b < 128 || $b > 191)
{
$str[$start] = $inv;
$i = $start;
break;
}
$bytes--;
}
}
}
}
}
return($str);
}

public static function utf8ize($mixed)
{
if(is_array($mixed) || is_object($mixed))
{
foreach($mixed as $key => $value)
{
$mixed[$key] = self::utf8ize($value);
}
}
else
if(is_string($mixed))
$mixed = self::mix2utf($mixed);
return($mixed);
}

private static function maybe_mb_convert_to_utf8($string) {
return function_exists('mb_convert_encoding') ? mb_convert_encoding($string, "UTF-8", "auto") : $string;
}
Expand Down