Пример #1
0
 /**
  * @param mixed             $value
  * @param null|false|string $encoding
  *
  * @return string|null
  */
 public static function escape(&$value, $encoding = null)
 {
     if (empty($value)) {
         return $value;
     }
     $kintEnabled = Kint::enabled();
     if ($kintEnabled === Kint::MODE_CLI) {
         $value = str_replace("", '\\x1b', $value);
     }
     if ($kintEnabled === Kint::MODE_CLI || $kintEnabled === Kint::MODE_WHITESPACE) {
         return $value;
     }
     if (!$encoding) {
         $encoding = self::_detectEncoding($value);
     }
     $value = htmlspecialchars($value, ENT_NOQUOTES, $encoding === 'ASCII' ? 'UTF-8' : $encoding);
     // TODO: we could make the symbols hover-title show the code for the invisible symbol
     if ($encoding === 'UTF-8') {
         # when possible force invisible characters to have some sort of display (experimental)
         $value = UTF8::remove_invisible_characters($value, false, '?');
     }
     # this call converts all non-ASCII characters into html chars of format
     $value = UTF8::html_encode($value, true, $encoding);
     return $value;
 }