PHP Article Spinner Script / Function

Method

Registered Member
Joined
Jan 30, 2010
Messages
89
Reaction score
12
Thought I'd make a little contribution don't really know where I'm supposed to post it so move it if necessary please.

Not all my work, just a little modified to work for me. Use [ and ] to enter spun words and seperate with a ,.

function spin($text) {
while (!(strpos($text,'[') === FALSE) && !(strpos($text,']') === FALSE)) {
$leftb = strpos($text,'[');
$rightb = strpos($text,']');
$spintext = split(',',substr($text,$leftb+1,$rightb-$leftb-1));
$spinselect = trim($spintext[mt_rand(0,count($spintext)-1)]);
$brackettext = substr($text,$leftb,($rightb-$leftb)+1);
$text = str_replace($brackettext,$spinselect,$text);
}
return $text;
}

TO USE IT:

$text = "[This,That,Them] Spun [Words,Fish,Sheep]";
$count = 0;
while ($count++ < 100) {
echo spin($text);
echo "<br />";
}
 
Last edited:
Back
Top