How can I remove all words from a string except the last one with PHP?
For example the string "Organic Black Olives"
would become "Olives"
.
Try this:
$str = "Organic Black Olives";
// get words list
$words = explode(' ', $str);
// get last word
$last_word = $words[count($words)-1];
echo $last_word;