What is the difference between preg_replace() and ereg_replace() in PHP?

The difference between preg_replace() and ereg_replace() in PHP is that preg_replace() uses Perl-compatible regular expressions while ereg_replace() uses POSIX-compatible regular expressions. This means that preg_replace() supports a wider range of regular expression features and is generally more powerful and flexible compared to ereg_replace(). It is recommended to use preg_replace() for better compatibility and performance.

// Using preg_replace() to replace a pattern in a string
$new_string = preg_replace('/pattern/', 'replacement', $original_string);