What are the potential pitfalls of using ereg_replace() in PHP functions?

The ereg_replace() function is deprecated in PHP and should not be used as it may lead to security vulnerabilities and compatibility issues with newer PHP versions. To solve this issue, it is recommended to use the preg_replace() function instead, which provides similar functionality but with better performance and support for regular expressions.

// Using preg_replace() instead of ereg_replace()
$pattern = '/pattern/';
$replacement = 'replacement';
$string = 'example string';

$result = preg_replace($pattern, $replacement, $string);
echo $result;