0

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??

3
  • So you want to find the 3rd word? Will all strings begin with "I like" Commented Jan 27, 2013 at 20:49
  • 1
    Bacon and jerking. What you get upto behind closed doors is your business. Commented Jan 27, 2013 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.. Commented Jan 27, 2013 at 20:49

1 Answer 1

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

This will get your third word from string.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.