Getting the last word of a string (resolved)

Author Topic: Getting the last word of a string (resolved)  (Read 372 times)

I thought if I had this string

$joe = "why am I here";

and I did :

$a = getWord($joe, getWordCount($joe));

$a would equal "here".

But for some reason when I echo it, it's blank.

however echo(getWordCount($joe)); results in  "4"

So why can't I do this, and if not, how do I get the last word of a string? there's firstWord() and restWords() but how would i get the last word?
« Last Edit: July 05, 2013, 01:14:37 PM by Pacnet2012³ »

getWord(%a, getWordCount(%a)-1);

getWordCount starts at 1

getWord(%a, getWordCount(%a)-1);

getWordCount starts at 1
Darn, I forgot that. Thanks!