str_replace()
replaces all occurrences of search string with a replacement string.
Syntax
str_replace(find, replace, string, count)
- find(required) – It specifies the value to find.
- replace(required) – It specifies the value to replace the value in find.
- string(required) – it specifies the string to be searched.
- count(optional) – it is the variable that counts the number of replacements.
For example
echo str_replace("world","John","Hello world!",$i); echo "Replacements #: $i";
This function works by the following rules:
- If the string to be searched is an array, it returns an array
- If the string to be searched is an array, find and replace is performed with every array element
- If both find and replace are arrays, and replace has fewer elements than find, an empty string will be used as replace
- If find is an array and replace is a string, the replace string will be used for every find value
Leave a Reply