The str_replace() function is used to replace a character with another character in PHP.
find = Value to search in the string
replace = Value to replace the find with
string = String to be search
count = Variable that counts the number of replacements (Optional)
In the example below we searched for the value Dublin and replaced with Galway.
$string = "Welcome to Dublin";
Welcome to Galway
Replacing with empty value.
We replaced the value Mr with an empty value
$string = "Welcome home Mr Green";
$search = "Mr";
$replace = "";
Welcome home Green
Searching an array and replacing its value with another value
$myarr = array("dog","cow","donkey","cat");
echo "<br>" . "Counter: $i"; //Count number of replacements
In this example, we search an array $myarr for the value "cow" and replace it with the value "zebra".
Array (  => dog  => zebra  => donkey  => cat )