What are the potential pitfalls of using preg_replace versus str_replace in PHP?

The potential pitfall of using preg_replace over str_replace in PHP is that preg_replace uses regular expressions, which can be more complex and slower than simple string replacement done by str_replace. To solve this issue, if you only need to replace a simple string with another, it's better to use str_replace for better performance.

// Using str_replace instead of preg_replace for simple string replacement
$string = "Hello, World!";
$new_string = str_replace("Hello", "Hi", $string);
echo $new_string;