What are some alternative methods to achieve the same result as ereg_replace in PHP?

The ereg_replace function in PHP is deprecated as of PHP 5.3.0 and removed in PHP 7.0.0. To achieve the same result as ereg_replace, you can use the preg_replace function with a proper regular expression pattern.

// Using preg_replace to achieve the same result as ereg_replace
$pattern = '/pattern/';
$replacement = 'replacement';
$string = 'original string';

$new_string = preg_replace($pattern, $replacement, $string);