Why can't token by a 0? A 0 should return the total amount of tokens if you're planning on replicating the actual $gettok method from mIRC.
Other then that good job. I've been working on something similar in C#, never got around to finishing.