Are there better alternatives to using eregi_replace in PHP4 for replacing part of a string within another string?

The eregi_replace function in PHP4 is deprecated and should be avoided. A better alternative is to use the preg_replace function with the 'i' modifier for case-insensitive matching. This will allow you to replace part of a string within another string without relying on deprecated functions.

$string = "Hello World!";
$pattern = "/world/i";
$replacement = "PHP";
$new_string = preg_replace($pattern, $replacement, $string);
echo $new_string; // Output: Hello PHP!