Take the 2-minute tour ×

Let's say I have this string:

I like bacon but nothing else

How would I extract "bacon" from the string? Like also this one:

I like jerking around

And that one would only get jerking?

Thanks! :)

Would this envolve regex maybe??

share|improve this question
So you want to find the 3rd word? Will all strings begin with "I like" –  FreshPrinceOfSO Jan 27 '13 at 20:49
Bacon and jerking. What you get upto behind closed doors is your business. –  hohner Jan 27 '13 at 20:49
Sure, or if it's always the third word you could: split the string and get the third part of the array or find the second and third space and use substr to grab that word.. –  hank Jan 27 '13 at 20:49
add comment

1 Answer

up vote 2 down vote accepted
$string = "I like bacon but nothing else";
$word = end(explode(" ", $string, 3));
echo $word;

This will get your third word from string.

share|improve this answer
this will work! :) thank you! :) –  user208829 Jan 27 '13 at 21:01
add comment

Your Answer


