Have you consider using explode?
explode split the string into array, then you can call the array piece by piece.
This is what I got from php manual:
array explode (string separator, string string [, int limit])
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode (" ", $pizza);