What are some alternative methods to achieve the same result as preg_replace with a function in PHP?

When we want to achieve the same result as preg_replace with a function in PHP, we can use the str_replace function as an alternative method. The str_replace function can be used to replace occurrences of a substring within a string. It is simpler to use than preg_replace in some cases, especially when dealing with simple string replacements.

// Using str_replace to achieve the same result as preg_replace
$string = "Hello, World!";
$newString = str_replace("Hello", "Hi", $string);
echo $newString; // Output: Hi, World!