Source Code:
(back to article)
<?php // PHP program for replacing all the occurences // of a word within a string // Given string $str = "w3docs is W3docs"; // Word to be replaced $w1 = "w3docs"; // Replaced by $w2 = "W3DOCS"; // Using str_replace() function // for replacing the word $str = str_replace($w1, $w2, $str); // Printing the result echo $str; ?>
Result:
Report an issue