What is the purpose of using ereg_replace() in PHP and what are the potential pitfalls associated with its usage?

The purpose of using ereg_replace() in PHP is to perform a regular expression search and replace on a string. However, ereg_replace() is deprecated as of PHP 5.3.0 and removed in PHP 7.0.0 due to performance and security reasons. It is recommended to use the preg_replace() function instead, which provides a more powerful and efficient way to perform regular expression search and replace.

// Using preg_replace() instead of ereg_replace()
$pattern = '/pattern/';
$replacement = 'replacement';
$string = 'original string';
$new_string = preg_replace($pattern, $replacement, $string);