You are here

protected function Escaper::jsMatcher in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-escaper/src/Escaper.php \Zend\Escaper\Escaper::jsMatcher()

Callback function for preg_replace_callback that applies Javascript escaping to all matches.

Parameters

array $matches:

Return value

string

File

vendor/zendframework/zend-escaper/src/Escaper.php, line 277

Class

Escaper
Context specific methods for use in secure output escaping

Namespace

Zend\Escaper

Code

protected function jsMatcher($matches) {
  $chr = $matches[0];
  if (strlen($chr) == 1) {
    return sprintf('\\x%02X', ord($chr));
  }
  $chr = $this
    ->convertEncoding($chr, 'UTF-16BE', 'UTF-8');
  return sprintf('\\u%04s', strtoupper(bin2hex($chr)));
}