Skip to content

Instantly share code, notes, and snippets.

@darkcolonist
Last active July 24, 2025 03:27
Show Gist options
  • Save darkcolonist/68285f4a009e84efc587 to your computer and use it in GitHub Desktop.
Save darkcolonist/68285f4a009e84efc587 to your computer and use it in GitHub Desktop.
utf8ize json encode fix
/**
* fixes the encoding of the values in an associative array
*
* usage:
* $formatted_rows = util::utf8ize($formatted_rows);
* echo json_encode($formatted_rows);
*
* @param assoc $arr array to be processed
* @return assoc processed array
*/
public static function utf8ize($arr){
if (is_array($arr)) {
foreach ($arr as $k => $v) {
$arr[$k] = self::utf8ize($v);
}
} else if (is_string ($arr)) {
return utf8_encode($arr);
}
return $arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment