You can replace all instance in a string using str_replace with the help of str_replace function.
In this example, str_replace replaces all instances of abc with xyz like this:
echo str_replace("abc","xyz","abcdefghijklmn");
the output will become : xyzdefghijklmn
Str_replace will also be used with arrays.
$fruitarr=array("apple","banana","orange");
$fruit2arr=array("Apple","Banana","Orange");
echo str_replace($a,$b,"apple,banana and orange are fruits);
The out put will become : Apple,Banana and Orange are fruits.
We can also use substr_replace function which replace part of the string with another string.
echo substr_replace("Apple","Banana",0); // 0 will start replacing at the first character in the string
0 Comment(s)