There are several ways but I think the best will be an array with explode :
$frase = "O + rato + roeu + a + roupa + do + rei + de + roma";
$palavras = explode('+', $frase);
Now it has an array, doing print_r($palavras);
:
Array ([0] => [ 1 ] => mouse [ = 2>] => roeu [3] => a [4] => garment [5] = > of [6] => king [7] = > of [8] = > roma)
You can access any of the words through your index within this array, base 0:
$palavras[0] = ' O ';
$palavras[1] = ' rato ';
...
If you want to rejoin them in a sentence without the addition signs, just do an implode :
$frase = implode('', $palavras); // não coloco espaço no primeiro argumento pois este já existe em cada uma das palavras do nosso array
And it stays:
The mouse gnawed at the clothes of the king of Rome
However doing what you asked, using the for loop and having a dynamic variable for each word (in this context I do not recommend) you can do:
$frase = "O + rato + roeu + a + roupa + do + rei + de + roma";
$palavras = explode('+', $frase);
for($i = 0, $count = count($palavras); $i < $count; $i++) {
$varNum = $i+1;
${'var' . $varNum} = $palavras[$i];
}
echo $var1; // O
...
echo $var9; // roma