You are here

function twig_replace_filter in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/lib/Twig/Extension/Core.php \twig_replace_filter()

Replaces strings within a string.

Parameters

string $str String to replace in:

array|Traversable $from Replace values:

string|null $to Replace to, deprecated (@see http://php.net/manual/en/function.strtr.php):

Return value

string

1 string reference to 'twig_replace_filter'
Twig_Extension_Core::getFilters in vendor/twig/twig/lib/Twig/Extension/Core.php

File

vendor/twig/twig/lib/Twig/Extension/Core.php, line 534

Code

function twig_replace_filter($str, $from, $to = null) {
  if ($from instanceof Traversable) {
    $from = iterator_to_array($from);
  }
  elseif (is_string($from) && is_string($to)) {
    @trigger_error('Using "replace" with character by character replacement is deprecated and will be removed in Twig 2.0', E_USER_DEPRECATED);
    return strtr($str, $from, $to);
  }
  elseif (!is_array($from)) {
    throw new Twig_Error_Runtime(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', is_object($from) ? get_class($from) : gettype($from)));
  }
  return strtr($str, $from);
}