Buyrun, çalışıyor:
$string = '{{The|A}} {{quick|speedy|fast}} {{brown|black|red}} {{fox|wolf}} {{jumped|bounded|hopped|skipped}} over the {{lazy|tired}} {{dog|hound}}';
echo '
<p><b>Toplam '.spin($string, false, true).'</b> permütasyon oluşturabilir....</p>
<p>Örneğin: ' . spin($string, false) . '</p>';
function spin($string, $seedPageName = true, $calculate = false, $openingConstruct = '{{', $closingConstruct = '}}', $separator = '|')
{
# Choose whether to return the string or the number of permutations
$return = 'string';
if($calculate)
{
$permutations = 1;
$return = 'permutations';
}
# If we have nothing to spin just exit (don't use a regexp)
if(strpos($string, $openingConstruct) === false)
{
return $$return;
}
if(preg_match_all('!'.$openingConstruct.'(.*?)'.$closingConstruct.'!s', $string, $matches))
{
# Optional, always show a particular combination on the page
if($seedPageName)
{
mt_srand(crc32($_SERVER['REQUEST_URI']));
}
$find = array();
$replace = array();
foreach($matches[0] as $key => $match)
{
$choices = explode($separator, $matches[1][$key]);
if($calculate)
{
$permutations *= count($choices);
}
else
{
$find[] = $match;
$replace[] = $choices[mt_rand(0, count($choices) - 1)];
}
}
if(!$calculate)
{
# Ensure multiple instances of the same spinning combinations will spin differently
$string = str_replace_first($find, $replace, $string);
}
}
return $$return;
}
# Similar to str_replace, but only replaces the first instance of the needle
function str_replace_first($find, $replace, $string)
{
# Ensure we are dealing with arrays
if(!is_array($find))
{
$find = array($find);
}
if(!is_array($replace))
{
$replace = array($replace);
}
foreach($find as $key => $value)
{
if(($pos = mb_strpos($string, $value)) !== false)
{
# If we have no replacement make it empty
if(!isset($replace[$key]))
{
$replace[$key] = '';
}
$string = mb_substr($string, 0, $pos).$replace[$key].mb_substr($string, $pos + mb_strlen($value));
}
}
return $string;
}.php uzantısıyla dosya olarak kayıt edip sunucunuza gönderin. Değişim yapılacak kelimeleri
{{bu|yada bu|yada yada bu}} şeklinde | karakteriyle birleştirerek yazıyorsunuz.