How can str_replace be integrated with preg_replace in PHP to achieve more complex text replacements?

When dealing with more complex text replacements in PHP, you can integrate `str_replace` with `preg_replace` to achieve the desired result. `str_replace` is useful for simple string replacements, while `preg_replace` allows for more advanced pattern matching using regular expressions. By combining the two functions, you can handle a wider range of text replacement scenarios.

// Example code snippet integrating str_replace with preg_replace
$text = "Hello, [name]! Today is [day].";
$replacements = array(
    '[name]' => 'John',
    '[day]' => 'Monday'
);

// Using str_replace to replace simple placeholders
foreach ($replacements as $search => $replace) {
    $text = str_replace($search, $replace, $text);
}

// Using preg_replace for more complex replacements
$text = preg_replace('/[a-zA-Z]+/', 'world', $text);

echo $text; // Output: Hello, world! world is world.