How can the str_replace() function in PHP be utilized to replace specific characters in a string?

To replace specific characters in a string using the str_replace() function in PHP, you need to provide the function with the character or characters you want to replace, the replacement character or characters, and the string in which the replacement should occur. This function can be useful for tasks like replacing all occurrences of a certain character in a string with another character.

// Example of using str_replace() to replace specific characters in a string
$string = "Hello, world!";
$new_string = str_replace(",", "!", $string);
echo $new_string; // Output: Hello! world!