What are the potential pitfalls of using multiple str_replace functions in a PHP script and how can they be avoided?

Using multiple str_replace functions in a PHP script can lead to unexpected results if the replacement strings overlap. To avoid this issue, you can use an array as the first argument of str_replace to perform multiple replacements in a single function call.

// Example of using an array with str_replace to avoid pitfalls
$string = "Hello world!";
$replacements = array(
    "Hello" => "Hi",
    "world" => "universe"
);
$new_string = str_replace(array_keys($replacements), array_values($replacements), $string);
echo $new_string; // Output: "Hi universe!"