March 9, 2013

how do i replace certain words in a sentence with php

Question by Imtiaz

Suppose I have this sentence: “The president obama came back to america from africa with his family”.

How do I replace “obama” with “bush”?

Answer by Starx

Using str_replace() functions:

$sentence = "The president obama came back to america from africa with his family";
$changed = str_replace("obama", "bush", $sentence);

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!