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.world';
2$var2 = str_replace(".", "-", $var1);
3echo $var2; // hello-world
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
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);
7echo("Now, this is the string after replacement: ");
8echo($mynewstring);
9?>
10