You are here

function _twig_escape_js_callback in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Twig/Extension/Core.php \_twig_escape_js_callback()
1 string reference to '_twig_escape_js_callback'
twig_escape_filter in vendor/Twig/Extension/Core.php
Escapes a string.

File

vendor/Twig/Extension/Core.php, line 1132

Code

function _twig_escape_js_callback($matches) {
  $char = $matches[0];

  // \xHH
  if (!isset($char[1])) {
    return '\\x' . strtoupper(substr('00' . bin2hex($char), -2));
  }

  // \uHHHH
  $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8');
  return '\\u' . strtoupper(substr('0000' . bin2hex($char), -4));
}