PHP Scripts replace string function str_replace()
This is a very good function to replace the word or string in string or text area, and very easy to handle the string.
<?php $string = "PHP-Scripts-string-change-function"; echo $string; ?>
//Output as below PHP-Scripts-string-change-function
Now replace the – into space
<?php $string = "PHP-Scripts-string-change-function"; $change = str_replace("-", " ", $string); ?>
Out put
PHP Scripts string change function
We can also use the array to change the string like below
<?php $string="I have two shirt one is blue and other is red color"; // we change the three word shirt to pent, blue to brown and red to yellow $oldword = array("shirt", "blue","red"); $newword = array("pent","brown","yellow"); $newstring = str_replace($oldword, $newword, $string); // Output now is // I have two pent one is brown and other is yellow color ?>
You can easily replace the world and string.