PHP str_replace() Function
PHP str_replace() Function
The str_replace() function in PHP replaces all occurrences of the search string with the specified replacement string. This function is case-sensitive.
Syntax
str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
Parameter
search(required)- This parameter signifies the value to search.
replace(required)- This parameter represents the replacement value that replaces found search values.
subject(required)- This parameter specifies the string to be searched.
count(optional)- This parameter signifies a variable that counts the number of replacements
Return
This function returns a string or an array with the replaced values.
Example 1
Output
The original string:Hello World! After the str_replace() function... New string: Hello world!
Example 2
Output
After using the str_replace()... Array ( [0] => T [1] => and )
Example 3
Output
Array ( [0] => Hello [1] => world [2] => $ )
