Skip to content

Kirby 6.0.0

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(Collection|array|string $string, string|array|Collection $search, string|array|Collection $replace, int|array $limit = -1): array|string

Parameters

Name Type Default Description
$stringrequired Kirby\Toolkit\Collectionorarrayorstring no default value String being replaced on (haystack); can be an array of multiple subject strings
$searchrequired stringorarray<string>orKirby\Toolkit\Collection no default value
$replacerequired stringorarray<string>orKirby\Toolkit\Collection no default value
$limit intorarray<int> -1 Maximum replacements for each search value, -1 for no limit

Return types

arrayorstring

Parent class

Kirby\Toolkit\Str