public function toUTF8($string)
    {
        /**
         * (8x except 85, 8C) + (9x except 9C) + (BC, BD, BE)
         */
        static $macchars = "\x81\x82\x83\x84\x86\x87\x88\x89\x8A\x8B\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9D\x9E\x9F\xBC\xBD\xBE";

        if (mb_convert_encoding(mb_convert_encoding($string, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32') == $string) {
            $mac = mb_convert_encoding($string, 'windows-1252', 'UTF-8');
            for ($i = strlen($mac); $i;) {
                if (strpos($macchars, $mac[ -- $i]) !== false) {
                    return(iconv('MACINTOSH', 'UTF-8', $mac));
                }
            }

            return($string);
        } else {
            for ($i = strlen($string); $i;) {
                if (strpos($macchars, $string[ -- $i]) !== false) {
                    return(iconv('MACINTOSH', 'UTF-8', $string));
                }
            }

            return(iconv('windows-1252', 'UTF-8', $string));
        }
    }
public function toUTF8($string)
    {
        /**
         * (8x except 85, 8C) + (9x except 9C) + (BC, BD, BE)
         */
        static $macchars = "\x81\x82\x83\x84\x86\x87\x88\x89\x8A\x8B\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9D\x9E\x9F\xBC\xBD\xBE";

        if (mb_convert_encoding(mb_convert_encoding($string, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32') == $string) {
            $mac = mb_convert_encoding($string, 'windows-1252', 'UTF-8');
            for ($i = strlen($mac); $i;) {
                if (strpos($macchars, $mac[ -- $i]) !== false) {
                    return(iconv('MACINTOSH', 'UTF-8', $mac));
                }
            }

            return($string);
        } else {
            for ($i = strlen($string); $i;) {
                if (strpos($macchars, $string[ -- $i]) !== false) {
                    return(iconv('MACINTOSH', 'UTF-8', $string));
                }
            }

            return(iconv('windows-1252', 'UTF-8', $string));
        }
    }
public function toUTF8 ( $ string ) { /**
         * (8x except 85, 8C) + (9x except 9C) + (BC, BD, BE)
         */ static $ macchars = "\x81\x82\x83\x84\x86\x87\x88\x89\x8A\x8B\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9D\x9E\x9F\xBC\xBD\xBE" ; if ( mb_convert_encoding ( mb_convert_encoding ( $ string , 'UTF-32' , 'UTF-8' ) , 'UTF-8' , 'UTF-32' ) == $ string ) { $ mac = mb_convert_encoding ( $ string , 'windows-1252' , 'UTF-8' ) ; for ( $ i = strlen ( $ mac ) ; $ i ; ) { if ( strpos ( $ macchars , $ mac [ -- $ i ] ) !== false ) { return ( iconv ( 'MACINTOSH' , 'UTF-8' , $ mac ) ) ; } } return ( $ string ) ; } else { for ( $ i = strlen ( $ string ) ; $ i ; ) { if ( strpos ( $ macchars , $ string [ -- $ i ] ) !== false ) { return ( iconv ( 'MACINTOSH' , 'UTF-8' , $ string ) ) ; } } return ( iconv ( 'windows-1252' , 'UTF-8' , $ string ) ) ; } }
Guess the charset of a string and returns the UTF-8 version

@param  string $string
@return string
Guess the charset of a string and returns the UTF - 8 version