The problem with the code, below, is that it removes characters from the string rather than the words.
<?php
$str = "In a minute, remove all of the corks from these bottles in the cellar";
$useless_words = array("the", "of", "or", "in", "a");
$newstr = str_replace($useless_words, "", $str);
//OUTPUT OF ABOVE: "In mute, remove ll cks from se bottles cellr"
?>
I need the output to be: minute, remove all corks from these bottles cellar
I'm assuming I can't use str_replace()
. What can I do to achieve this?
.