Spinned:
This was the best party evor!
Source:
This [is,was,has been,can be] the [best, worst, stupidest] [party,dance,code,monkey,movie] evor!
Average percentage difference over 10 spins: 26.2%
Here's the php function:
function spin($text) {
//While there's pairs of square brackets, spin whats inside of them
while (!(strpos($text,'[') === FALSE) && !(strpos($text,']') === FALSE)) {
//Find the first '['
$leftb = strpos($text,'[');
//Find the first ']'
$rightb = strpos($text,']');
//Split the string up, then (psudo)randomise the item chosen
$spintext = split(',',substr($text,$leftb+1,$rightb-$leftb-1));
$spinselect = trim($spintext[mt_rand(0,count($spintext)-1)]);
//Get the whole string to replace including the brackets
$brackettext = substr($text,$leftb,($rightb-$leftb)+1);
//Replace the [blah,blah2] with whatever item is chosen
$text = str_replace($brackettext,$spinselect,$text);
}
//return the block of modified text
return $text;
}
This code is written by Kythin and comes AS IS with ABSOLUTELY NO SUPPORT OR WARRANTEES OR ANYTHING LIKE THAT.
Download the code from this page in a zip file