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
Related posts:
- Sending an email in PHP Simple Mail <!–p$subject = “Test mail”; $message = “Hello! This is a simple email message.”; $from = “someonelse@example.com”; $headers = “From: $from”; mail($to,$subject,$message,$headers); echo...
- Random Password Generator PHP password generator is a complete, working random password generation function for PHP. It allows the developer to customize the password: set its length...



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