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

Related posts:

  1. 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...
  2. 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...

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