andy
answered Apr 25 '23 00:00
In PHP, str_replace() is a built-in function used to replace all occurrences of a substring in a given string with another substring. Its syntax is:
str_replace($search, $replace, $subject);
.$search : the substring to search for.
.$replace: the substring to replace with.
.$subject: the original string.
Here's an example of how to use str_replace( ):
$string = "The quick brown fox jumps over the lazy dog.";
$new_string = str_replace("fox", "cat", $string);
echo $new_string; // The quick brown cat jumps over the lazy dog.
In this example, str_replace() is used to replace the substring "fox" with "cat" in the original string, producing the output "The quick brown cat jumps over the lazy dog."