1<?php
2//str_replace("Original Value", "Value to be replaced", "String");
3$result = str_replace("1", "2", "This is number 1");
4// Output: This is number 2
5?>
1$var1 = 'hello_john';
2$var2 = str_replace("_", "-", $var1);
3echo $var2; // hello-john
1<?php
2$string = str_ireplace("FoX", "CAT", "the quick brown fox jumps over the lazy dog");
3echo $string; // the quick brown CAT jumps over the lazy dog
4?>
1phpCopy<?php
2$mystring = "This is my string.";
3echo("This is the string before replacement: ");
4echo($mystring);
5echo("\n");
6$mynewstring = str_replace(" my ", " ", $mystring, $count);
7echo("Now, this is the string after replacement: ");
8echo($mynewstring);
9echo("\n");
10echo("The number of replacements is: ");
11echo($count);
12?>
13