What are the potential pitfalls of using eregi_replace in PHP scripts and how can they be avoided?

Using eregi_replace in PHP scripts is not recommended as it is deprecated and has been removed in PHP 7. Instead, it is recommended to use the preg_replace function with the 'i' modifier to perform a case-insensitive search and replace.

// Replace eregi_replace with preg_replace with 'i' modifier
$pattern = '/pattern/i';
$replacement = 'replacement';
$string = 'example string';
$result = preg_replace($pattern, $replacement, $string);
echo $result;