public static function multiByteEntities($mixed, $entity = false)
    {
        static $hasIconV;
        static $limit;
        if (!isset($hasIconV)) {
            // safe resource check
            $hasIconV = function_exists('iconv');
        }

        if (!isset($limit)) {
            $limit = @ini_get('pcre.backtrack_limit');
            $limit = ! is_numeric($limit) ? 4096 : abs($limit);
            // minimum regex is 512 byte
            $limit = $limit < 512 ? 512 : $limit;
            // limit into 40 KB
            $limit = $limit > 40960 ? 40960 : $limit;
        }

        if (! $hasIconV && ! $entity) {
            return $mixed;
        }

        if (is_array($mixed)) {
            foreach ($mixed as $key => $value) {
                $mixed[$key] = self::multiByteEntities($value, $entity);
            }
        } elseif (is_object($mixed)) {
            foreach (get_object_vars($mixed) as $key => $value) {
                $mixed->{$key} = self::multiByteEntities($value, $entity);
            }
        } /**
         * Work Safe with Parse @uses @var $limit Bit
         * | 4KB data split for regex callback & safe memory usage
         * that maybe fail on very long string
         */
        elseif (strlen($mixed) > $limit) {
            return implode('', self::multiByteEntities(str_split($mixed, $limit), $entity));
        }

        if ($entity) {
            $mixed = htmlentities(html_entity_decode($mixed));
        }

        return $hasIconV
            ? (
            preg_replace_callback(
                '/[\x{80}-\x{10FFFF}]/u',
                function ($match) {
                    $char = current($match);
                    $utf = iconv('UTF-8', 'UCS-4//IGNORE', $char);
                    return sprintf("&#x%s;", ltrim(strtolower(bin2hex($utf)), "0"));
                },
                $mixed
            ) ?:$mixed
            ) : $mixed;
    }