private function detectEncoding($string)
    {
        static $enclist = ['UTF-8', 'ASCII', 'ISO-8859-1', 'Windows-1252'];
        if (function_exists('mb_detect_encoding')) {
            return mb_detect_encoding($string, $enclist, true);
        }
        $result = false;
        foreach ($enclist as $item) {
            try {
                $sample = iconv($item, $item, $string);
                if (md5($sample) === md5($string)) {
                    $result = $item;
                    break;
                }
            } catch (ContextErrorException $e) {
                unset($e);
            }
        }

        return $result;
    }
private function detectEncoding($string)
    {
        static $enclist = ['UTF-8', 'ASCII', 'ISO-8859-1', 'Windows-1252'];
        if (function_exists('mb_detect_encoding')) {
            return mb_detect_encoding($string, $enclist, true);
        }
        $result = false;
        foreach ($enclist as $item) {
            try {
                $sample = iconv($item, $item, $string);
                if (md5($sample) === md5($string)) {
                    $result = $item;
                    break;
                }
            } catch (ContextErrorException $e) {
                unset($e);
            }
        }

        return $result;
    }
private function detectEncoding ( $ string ) { static $ enclist = [ 'UTF-8' , 'ASCII' , 'ISO-8859-1' , 'Windows-1252' ] ; if ( function_exists ( 'mb_detect_encoding' ) ) { return mb_detect_encoding ( $ string , $ enclist , true ) ; } $ result = false ; foreach ( $ enclist as $ item ) { try { $ sample = iconv ( $ item , $ item , $ string ) ; if ( md5 ( $ sample ) === md5 ( $ string ) ) { $ result = $ item ; break ; } } catch ( ContextErrorException $ e ) { unset ( $ e ) ; } } return $ result ; }
Detect if encoding is UTF-8, ASCII, ISO-8859-1 or Windows-1252.

@param $string

@return bool|string
Detect if encoding is UTF - 8 ASCII ISO - 8859 - 1 or Windows - 1252 .