$val) { if (is_string($key)) { $key = static::sanitizeUtf8String($key); } $sanitized[$key] = static::sanitizeUtf8Recursive($val); } return $sanitized; case 'object': $sanitized = array(); foreach ($value as $key => $val) { if (is_string($key)) { $key = static::sanitizeUtf8String($key); } $sanitized[$key] = static::sanitizeUtf8Recursive($val); } return (object) $sanitized; default: return $value; } } /** * Replace bad byte sequences in the given UTF-8 string with question marks * * @param string $string * * @return string */ protected static function sanitizeUtf8String($string) { return mb_convert_encoding($string, 'UTF-8', 'UTF-8'); } }