You are here

public function Iconv::convert in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-stdlib/src/StringWrapper/Iconv.php \Zend\Stdlib\StringWrapper\Iconv::convert()

Convert a string from defined encoding to the defined convert encoding

Parameters

string $str:

bool $reverse:

Return value

string|false

Overrides AbstractStringWrapper::convert

File

vendor/zendframework/zend-stdlib/src/StringWrapper/Iconv.php, line 268

Class

Iconv

Namespace

Zend\Stdlib\StringWrapper

Code

public function convert($str, $reverse = false) {
  $encoding = $this
    ->getEncoding();
  $convertEncoding = $this
    ->getConvertEncoding();
  if ($convertEncoding === null) {
    throw new Exception\LogicException('No convert encoding defined');
  }
  if ($encoding === $convertEncoding) {
    return $str;
  }
  $fromEncoding = $reverse ? $convertEncoding : $encoding;
  $toEncoding = $reverse ? $encoding : $convertEncoding;

  // automatically add "//IGNORE" to not stop converting on invalid characters
  // invalid characters triggers a notice anyway
  return iconv($fromEncoding, $toEncoding . '//IGNORE', $str);
}