public function utf82utf16($utf8)
    {
        // oh please oh please oh please oh please oh please
        if ($this->_mb_convert_encoding) {
            return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
        }

        switch ($this->strlen8($utf8)) {
            case 1:
                // this case should never be reached, because we are in ASCII range
                // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                return $utf8;

            case 2:
                // return a UTF-16 character from a 2-byte UTF-8 char
                // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                return chr(0x07 & (ord($utf8{0}) >> 2))
                .chr((0xC0 & (ord($utf8{0}) << 6))
                    | (0x3F & ord($utf8{1})));

            case 3:
                // return a UTF-16 character from a 3-byte UTF-8 char
                // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                return chr((0xF0 & (ord($utf8{0}) << 4))
                    | (0x0F & (ord($utf8{1}) >> 2)))
                .chr((0xC0 & (ord($utf8{1}) << 6))
                    | (0x7F & ord($utf8{2})));
        }

        // ignoring UTF-32 for now, sorry
        return '';
    }
public function utf82utf16($utf8)
    {
        // oh please oh please oh please oh please oh please
        if ($this->_mb_convert_encoding) {
            return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
        }

        switch ($this->strlen8($utf8)) {
            case 1:
                // this case should never be reached, because we are in ASCII range
                // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                return $utf8;

            case 2:
                // return a UTF-16 character from a 2-byte UTF-8 char
                // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                return chr(0x07 & (ord($utf8{0}) >> 2))
                .chr((0xC0 & (ord($utf8{0}) << 6))
                    | (0x3F & ord($utf8{1})));

            case 3:
                // return a UTF-16 character from a 3-byte UTF-8 char
                // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                return chr((0xF0 & (ord($utf8{0}) << 4))
                    | (0x0F & (ord($utf8{1}) >> 2)))
                .chr((0xC0 & (ord($utf8{1}) << 6))
                    | (0x7F & ord($utf8{2})));
        }

        // ignoring UTF-32 for now, sorry
        return '';
    }
public function utf82utf16 ( $ utf8 ) { // oh please oh please oh please oh please oh please if ( $ this -> _mb_convert_encoding ) { return mb_convert_encoding ( $ utf8 , 'UTF-16' , 'UTF-8' ) ; } switch ( $ this -> strlen8 ( $ utf8 ) ) { case 1 : // this case should never be reached, because we are in ASCII range // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 return $ utf8 ; case 2 : // return a UTF-16 character from a 2-byte UTF-8 char // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 return chr ( 0x07 & ( ord ( $ utf8 { 0 } ) >> 2 ) ) . chr ( ( 0xC0 & ( ord ( $ utf8 { 0 } ) << 6 ) ) | ( 0x3F & ord ( $ utf8 { 1 } ) ) ) ; case 3 : // return a UTF-16 character from a 3-byte UTF-8 char // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 return chr ( ( 0xF0 & ( ord ( $ utf8 { 0 } ) << 4 ) ) | ( 0x0F & ( ord ( $ utf8 { 1 } ) >> 2 ) ) ) . chr ( ( 0xC0 & ( ord ( $ utf8 { 1 } ) << 6 ) ) | ( 0x7F & ord ( $ utf8 { 2 } ) ) ) ; } // ignoring UTF-32 for now, sorry return '' ; }
convert a string from one UTF-8 char to one UTF-16 char.

Normally should be handled by mb_convert_encoding, but
provides a slower PHP-only method for installations
that lack the multibye string extension.

@param string $utf8 UTF-8 character

@return string UTF-16 character
convert a string from one UTF - 8 char to one UTF - 16 char .