Skip to content

Kirby 4.4.1

Str::replace()

Replaces all or some occurrences of the search string with the replacement string Extension of the str_replace() function in PHP with an additional $limit parameter

Str::replace(Kirby\Toolkit\Collection|array|string $string, Kirby\Toolkit\Collection|array|string $search, Kirby\Toolkit\Collection|array|string $replace, array|int $limit = -1): array|string

Parameters

Name Type Default Description
$string * Kirby\Toolkit\Collection|array|string String being replaced on (haystack); can be an array of multiple subject strings
$search * Kirby\Toolkit\Collection|array|string Value being searched for (needle)
$replace * Kirby\Toolkit\Collection|array|string Value to replace matches with
$limit array|int -1 Maximum possible replacements for each search value;
multiple limits for each search value are supported;
defaults to no limit

Return type

array|string

Parent class

Kirby\Toolkit\Str