function kintParser::escape

7 calls to kintParser::escape()
kintParser::_parse_array in kint/kint/inc/kintParser.class.php
kintParser::_parse_object in kint/kint/inc/kintParser.class.php
kintParser::_parse_string in kint/kint/inc/kintParser.class.php
Kint_Decorators_Plain::_drawHeader in kint/kint/decorators/plain.php
Kint_Decorators_Plain::_title in kint/kint/decorators/plain.php

... See full list

File

kint/kint/inc/kintParser.class.php, line 237

Class

kintParser

Code

public static function escape($value, $encoding = null) {
    if (empty($value)) {
        return $value;
    }
    if (Kint::enabled() === Kint::MODE_CLI) {
        $value = str_replace("\x1b", "\\x1b", $value);
    }
    if (Kint::enabled() === Kint::MODE_CLI || Kint::enabled() === Kint::MODE_WHITESPACE) {
        return $value;
    }
    $encoding or $encoding = self::_detectEncoding($value);
    $value = htmlspecialchars($value, ENT_NOQUOTES, $encoding === 'ASCII' ? 'UTF-8' : $encoding);
    if ($encoding === 'UTF-8') {
        // todo we could make the symbols hover-title show the code for the invisible symbol
        
        # when possible force invisible characters to have some sort of display (experimental)
        $value = preg_replace('/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x80-\\x9F]/u', '?', $value);
    }
    
    # this call converts all non-ASCII characters into html chars of format
    if (function_exists('mb_encode_numericentity')) {
        $value = mb_encode_numericentity($value, array(
            0x80,
            0xffff,
            0,
            0xffff,
        ), $encoding);
    }
    return $value;
}