What are some PHP string functions that can help with replacing parts of a string?

When working with strings in PHP, there are several built-in functions that can help with replacing parts of a string. Some commonly used functions include `str_replace()`, `substr_replace()`, and `preg_replace()`. These functions allow you to search for specific substrings within a string and replace them with another substring.

// Using str_replace() to replace a substring within a string
$string = "Hello, World!";
$new_string = str_replace("Hello", "Hi", $string);
echo $new_string;

// Using substr_replace() to replace a substring within a string at a specific position
$string = "Hello, World!";
$new_string = substr_replace($string, "Hi", 0, 5);
echo $new_string;

// Using preg_replace() to replace a substring within a string using a regular expression
$string = "Hello, World!";
$new_string = preg_replace("/Hello/", "Hi", $string);
echo $new_string;