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(string|array|Collection $string, string|array|Collection $search, string|array|Collection $replace, int|array $limit = -1): string|array
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| $stringrequired | stringorarrayorCollection |
no default value | String being replaced on (haystack); can be an array of multiple subject strings |
| $searchrequired | stringorarrayorCollection |
no default value | Value being searched for (needle) |
| $replacerequired | stringorarrayorCollection |
no default value | Value to replace matches with |
| $limit | intorarray |
-1
|
Maximum possible replacements for each search value; multiple limits for each search value are supported; defaults to no limit |
Return types
stringorarray
String with replaced values; if $string is an array, array of strings