PHP

Replace a word with another using php



Here is the code snippet in php to scan a text and replace the occurance of a particular word with another

Click here to see the code

<?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

Share

Thanks for reading my blog. If you like what I write, why not subscribe to my feed?

If you are busy, I can send the latest post to your email. Just subscribe to my email updates.

 

Enter your email address:

Delivered by FeedBurner

Discussion

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

Post a comment