replace

Replace parts of strings

Definition

string replace(string $input, string $old, string $new)

Replaces occurrences of $old within $input with $new and return the resulting string.

Parameters

string $input

String to replace substrings in.

string $old

Substring of $input to be replaced.

string $new

String to replace the occurrences of $old within $input with.

Returns

string

$input with all the occurrences of $old replaced with $new.

Examples

{
  a: replace('This is wrong!', 'wrong', 'correct'),
  b: replace('Line1\nLine2', '\n', ''),
  c: replace('-Hyphenated-String-', '-', `null`)
}
{
  "a": "This is correct!",
  "b": "Line1Line2",
  "c": "HyphenatedString"
}