How can regular expressions be used to solve the problem of str_replace distinguishing between uppercase and lowercase letters in PHP?

Regular expressions can be used in PHP to solve the problem of `str_replace` distinguishing between uppercase and lowercase letters by using the `preg_replace` function with the `i` modifier, which makes the pattern case-insensitive. This allows for a more flexible and accurate replacement of text regardless of the letter case.

$text = "Hello World";
$pattern = "/world/i";
$replacement = "PHP";
$result = preg_replace($pattern, $replacement, $text);
echo $result; // Output: Hello PHP