The str_replace() is a built-in function in PHP and is used to replace all the occurrences of the search string or array of search strings by replacement string or array of replacement strings in the given string or array respectively.
Syntax:
str_replace ( $searchVal, $replaceVal, $subjectVal, $count )
Parameters: This function accepts four parameters out of which 3 are mandatory and 1 is optional. All of these parameters are described below:
If the $searchVal and the $replaceVal arguments are arrays, then all the elements of the $searchVal argument are searched in the $subjectVal string and replaced by the corresponding elements in the $replaceVal argument. If number of elements in $replaceVal is less than that in $searchVal array, then if there are any occurrences of the additional elements of $searchVal argument in the $subjectVal argument then they will be replaced by an empty string. If the $subjectVal parameter is also an array instead of string then all of the elements of $subjectVal will be searched.
Top comments (0)