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

        $bytes = (ord($utf16{0}) << 8) | ord($utf16{1});

        switch (true) {
            case (0x7F & $bytes) == $bytes:
                // 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 chr(0x7F & $bytes);

            case (0x07FF & $bytes) == $bytes:
                // return a 2-byte UTF-8 character
                // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                return chr(0xC0 | (($bytes >> 6) & 0x1F))
                .chr(0x80 | ($bytes & 0x3F));

            case (0xFFFF & $bytes) == $bytes:
                // return a 3-byte UTF-8 character
                // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                return chr(0xE0 | (($bytes >> 12) & 0x0F))
                .chr(0x80 | (($bytes >> 6) & 0x3F))
                .chr(0x80 | ($bytes & 0x3F));
        }

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

        $bytes = (ord($utf16{0}) << 8) | ord($utf16{1});

        switch (true) {
            case (0x7F & $bytes) == $bytes:
                // 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 chr(0x7F & $bytes);

            case (0x07FF & $bytes) == $bytes:
                // return a 2-byte UTF-8 character
                // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                return chr(0xC0 | (($bytes >> 6) & 0x1F))
                .chr(0x80 | ($bytes & 0x3F));

            case (0xFFFF & $bytes) == $bytes:
                // return a 3-byte UTF-8 character
                // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                return chr(0xE0 | (($bytes >> 12) & 0x0F))
                .chr(0x80 | (($bytes >> 6) & 0x3F))
                .chr(0x80 | ($bytes & 0x3F));
        }

        // ignoring UTF-32 for now, sorry
        return '';
    }
public function utf162utf8 ( $ utf16 ) { // oh please oh please oh please oh please oh please if ( $ this -> _mb_convert_encoding ) { return mb_convert_encoding ( $ utf16 , 'UTF-8' , 'UTF-16' ) ; } $ bytes = ( ord ( $ utf16 { 0 } ) << 8 ) | ord ( $ utf16 { 1 } ) ; switch ( true ) { case ( 0x7F & $ bytes ) == $ bytes : // 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 chr ( 0x7F & $ bytes ) ; case ( 0x07FF & $ bytes ) == $ bytes : // return a 2-byte UTF-8 character // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 return chr ( 0xC0 | ( ( $ bytes >> 6 ) & 0x1F ) ) . chr ( 0x80 | ( $ bytes & 0x3F ) ) ; case ( 0xFFFF & $ bytes ) == $ bytes : // return a 3-byte UTF-8 character // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 return chr ( 0xE0 | ( ( $ bytes >> 12 ) & 0x0F ) ) . chr ( 0x80 | ( ( $ bytes >> 6 ) & 0x3F ) ) . chr ( 0x80 | ( $ bytes & 0x3F ) ) ; } // ignoring UTF-32 for now, sorry return '' ; }
convert a string from one UTF-16 char to one UTF-8 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 $utf16 UTF-16 character

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