Source Code:
(back to article)
<?php // PHP program for replacing // a word within a string // Given string $str = "geeks is W3docs Somegeeks"; // Replaced by $w2 = "W3DOCS"; // Use preg_replace() function // for replacing the word `geeks` with `W3DOCS` $str = preg_replace('/\bgeeks\b/', $w2, $str); // Print the result echo $str; ?>
Result:
Report an issue