You are here

protected function Escaper::convertEncoding in Zircon Profile 8

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

Encoding conversion helper which wraps iconv and mbstring where they exist or throws and exception where neither is available.

Parameters

string $string:

string $to:

array|string $from:

Return value

string

Throws

Exception\RuntimeException

5 calls to Escaper::convertEncoding()
Escaper::cssMatcher in vendor/zendframework/zend-escaper/src/Escaper.php
Callback function for preg_replace_callback that applies CSS escaping to all matches.
Escaper::fromUtf8 in vendor/zendframework/zend-escaper/src/Escaper.php
Converts a string from UTF-8 to the base encoding. The base encoding is set via this class' constructor.
Escaper::htmlAttrMatcher in vendor/zendframework/zend-escaper/src/Escaper.php
Callback function for preg_replace_callback that applies HTML Attribute escaping to all matches.
Escaper::jsMatcher in vendor/zendframework/zend-escaper/src/Escaper.php
Callback function for preg_replace_callback that applies Javascript escaping to all matches.
Escaper::toUtf8 in vendor/zendframework/zend-escaper/src/Escaper.php
Converts a string to UTF-8 from the base encoding. The base encoding is set via this class' constructor.

File

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

Class

Escaper
Context specific methods for use in secure output escaping

Namespace

Zend\Escaper

Code

protected function convertEncoding($string, $to, $from) {
  if (function_exists('iconv')) {
    $result = iconv($from, $to, $string);
  }
  elseif (function_exists('mb_convert_encoding')) {
    $result = mb_convert_encoding($string, $to, $from);
  }
  else {
    throw new Exception\RuntimeException(get_class($this) . ' requires either the iconv or mbstring extension to be installed' . ' when escaping for non UTF-8 strings.');
  }
  if ($result === false) {
    return '';

    // return non-fatal blank string on encoding errors from users
  }
  return $result;
}