What are the potential pitfalls of using ereg_replace versus str_replace in PHP for text replacement?

The potential pitfall of using ereg_replace in PHP for text replacement is that it is a deprecated function as of PHP 5.3.0 and removed in PHP 7.0.0. It is recommended to use the str_replace function instead, which is more efficient and widely supported. To fix this issue, replace ereg_replace with str_replace in your code.

// Incorrect usage of ereg_replace
$text = "Hello, World!";
$new_text = ereg_replace("Hello", "Hi", $text);

// Corrected code using str_replace
$text = "Hello, World!";
$new_text = str_replace("Hello", "Hi", $text);