Here is the code snippet in php to scan a text and replace the occurance of a particular word with another
<?php
// The text string
$text = "This is the text.";
// The word we want to replace with a new text
$oldWord = "the";
// The new word we want in place of the old one
$newWord = "a";
// Run through the text and replaces all occurrences of $oldText
$text = str_replace($oldWord , $newWord , $text);
// Display the new text
echo $text;
?>
Note : This function cant recognize some characters like ‘<' , '>‘ etc

Discussion
No comments for “Replace a word with another using php”