Splitting strings

What if I have a string like these?

DANIEL JOHNS - GUITARIST - SILVERCHAIR

And I want to get just the word GUITARIST
from the string? How I supposed to do it?

Will I do 2 strpos?

Actually I tried 2 strpos already but on the second one, the dash is still there. so I got
the position of the first “-” again, thus generating an error.

or there is a shorter way to do it?

Thanks guys

You could try this:


$str = 'DANIEL JOHNS - GUITARIST - SILVERCHAIR';
$segm = explode('-', $str);
$word = trim($segm[1]);

This will get you the second section of the string delimited by -.

You could also use substr() but then you have to know exactly from which to which position you need to extract the word.

Thanks LemonJuice! It worked! Solved…

You guys are the best.