What is the purpose of using ereg_replace in PHP code?

The ereg_replace function in PHP is used to perform a regular expression search and replace on a string. This function is particularly useful when you need to search for a pattern within a string and replace it with another value. Example PHP code snippet:

$string = "Hello, world!";
$new_string = ereg_replace("world", "PHP", $string);
echo $new_string; // Output: Hello, PHP!