How can str_replace() be utilized in PHP to replace or remove specific words from a text?

To replace or remove specific words from a text in PHP, you can use the str_replace() function. This function takes three parameters: the word or phrase you want to replace, the replacement word or phrase, and the original text. If you want to remove a word, you can simply pass an empty string as the replacement.

// Original text
$text = "The quick brown fox jumps over the lazy dog.";

// Replace 'fox' with 'cat'
$new_text = str_replace('fox', 'cat', $text);

// Remove 'lazy'
$new_text = str_replace('lazy', '', $new_text);

echo $new_text;