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
1
2<?php
3$var = 'ABCDEFGH:/MNRPQR/';
4echo "Original: $var<hr />\n";
5
6/* These two examples replace all of $var with 'bob'. */
7echo substr_replace($var, 'bob', 0) . "<br />\n";
8echo substr_replace($var, 'bob', 0, strlen($var)) . "<br />\n";
9
10/* Insert 'bob' right at the beginning of $var. */
11echo substr_replace($var, 'bob', 0, 0) . "<br />\n";
12
13/* These next two replace 'MNRPQR' in $var with 'bob'. */
14echo substr_replace($var, 'bob', 10, -1) . "<br />\n";
15echo substr_replace($var, 'bob', -7, -1) . "<br />\n";
16
17/* Delete 'MNRPQR' from $var. */
18echo substr_replace($var, '', 10, -1) . "<br />\n";
19?>
20
21