function kintVariableData::_detectEncoding

4 calls to kintVariableData::_detectEncoding()
kintParser::escape in kint/kint/inc/kintParser.class.php
kintParser::_parse_string in kint/kint/inc/kintParser.class.php
kintVariableData::_strlen in kint/kint/inc/kintVariableData.class.php
kintVariableData::_substr in kint/kint/inc/kintVariableData.class.php

File

kint/kint/inc/kintVariableData.class.php, line 45

Class

kintVariableData

Code

protected static function _detectEncoding($value) {
    $ret = null;
    if (function_exists('mb_detect_encoding')) {
        $mbDetected = mb_detect_encoding($value);
        if ($mbDetected === 'ASCII') {
            return 'ASCII';
        }
    }
    if (!function_exists('iconv')) {
        return !empty($mbDetected) ? $mbDetected : 'UTF-8';
    }
    $md5 = md5($value);
    foreach (Kint::$charEncodings as $encoding) {
        
        # fuck knows why, //IGNORE and //TRANSLIT still throw notice
        if (md5(@iconv($encoding, $encoding, $value)) === $md5) {
            return $encoding;
        }
    }
    return 'ASCII';
}