1. Don't use PHP.
If you really have to use PHP then
2. str_split turns "R2 F2 B2" into array("R","2"," ","F","2"," ","B","2"), which is not what you want. Use
$charArray = explode(" ",$chars);
3. Add a space at the end of each move, so
$result .= " ".$charArray[$randItem];
Live Instance of...