What are some common methods in PHP to delete specific parts of a string?
To delete specific parts of a string in PHP, you can use functions like `str_replace()`, `substr_replace()`, or regular expressions with `preg_replace()`. These functions allow you to search for a specific substring within a string and replace it with another substring or remove it altogether.
// Using str_replace() to delete specific substring from a string
$string = "Hello, World!";
$substring = "Hello, ";
$newString = str_replace($substring, "", $string);
echo $newString;
// Using substr_replace() to delete specific part of a string
$string = "Hello, World!";
$newString = substr_replace($string, "", 0, 6);
echo $newString;
// Using preg_replace() with regular expressions to delete specific part of a string
$string = "Hello, World!";
$pattern = "/Hello, /";
$newString = preg_replace($pattern, "", $string);
echo $newString;