What is the difference between eregi_replace and preg_replace in PHP?

The main difference between eregi_replace and preg_replace in PHP is that eregi_replace is case-insensitive while preg_replace is case-sensitive. This means that eregi_replace ignores the case of the characters in the search pattern, while preg_replace considers the case of the characters. If you need a case-insensitive search and replace operation, you should use eregi_replace, but if you need a case-sensitive operation, then preg_replace is the appropriate choice.

// Using eregi_replace for case-insensitive search and replace
$string = "Hello World";
$newString = eregi_replace("hello", "hi", $string);
echo $newString;

// Using preg_replace for case-sensitive search and replace
$string = "Hello World";
$newString = preg_replace("/Hello/", "Hi", $string);
echo $newString;