PHP str_replace() Function

The str_replace() function replaces some characters with some other characters in a string.

str_replace — Replace all occurrences of the search string with the replacement string

str_replace ( $search ,$replace , $string, $count)

$search – Required. Specifies the value to
$replace – Required. Specifies the value to replace the value in $search
$string – Required. Specifies the string to be searched
$count – Optional. A variable that counts the number of replacements

This function is case-sensitive. Use str_ireplace() to perform a case-insensitive search.


$string = str_replace(“things”,”sources”,”Learn webdevelopment things”);
echo $string;

The output of the code above will be:
Learn webdevelopment sources

Posted in Php