Replace (limited) occurrences of the search string with the replacement string.

Very alike to PHP's function str_replace(...), but with the major difference that this string_replace(...)-function's number of replacements can be limited!

Syntax

string_replace(string $search, string $replace, ?string $subject, int $limit = -1, int $offset = 0): ?string

  • $search
    The value being searched for, otherwise known as the needle.

  • $replace
    The replacement value that replaces found search values.

  • $subject
    The string being searched and replaced on, otherwise known as the haystack.
    If it is NULL, this is also returned.

  • $limit
    Limits the number of replacements. Any negative number is interpreted as: no-limit.

  • $offset
    If specified, search will start this number of characters counted from the beginning of the string.