i want to make a spin function to spin a string but i fased problem for doing it. I allready know how to sping words in string like changing {hi|hello} but what i want is different it is ranom spin in a string
$spin_words=array('Word1','Word2','Word3');
$text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
so i want to add the words in random like
Lorem Ipsum is simply [Word1] dummy text of the printing and typesetting industry.
or
Lorem Ipsum is simply dummy text of the printing [Word2] and typesetting industry.
or
Lorem Ipsum is simply dummy text of the printing and typesetting industry [Word3].
so any help guys
regards
You can try
$words = array('Word1','Word2','Word3');
$text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
echo wordInString($text,$words);
echo wordInString($text,$words);
Output Example
Lorem Ipsum is simply dummy Word1 text of the printing and typesetting industry.
Lorem Ipsum is simply dummy text of the printing Word2 and typesetting industry.
Function Used
function wordInString($text,array $words) {
$textNew = array();
$p = mt_rand(0, substr_count($text, " "));
$tok = strtok($text, "
\t");
$x = 1;
while ( $tok !== false ) {
$textNew[] = $tok and $x == $p and $textNew[] = $words[array_rand($words, 1)];
$tok = strtok(" ");
$x ++;
}
return implode(" ", $textNew);
}