Hi guys,
Just spent 5 minutes knocking this up, you pass it some text in spinnable format, and it outputs a spun version:
Sample input: I am a {little|small|tiny|big fat}, {lovely|nice|horrible|smelly} {cow|bovine|bull} and I {say|shout} {moo|moo moo moo} to you!
Hope someone gets some use from it
Just spent 5 minutes knocking this up, you pass it some text in spinnable format, and it outputs a spun version:
PHP:
<?php
function get_spin($input)
{
$pos = strpos($input, '{');
$output = substr($input, 0, $pos);
while($pos)
{
$close_pos = strpos($input, '}', $pos);
$diff = $close_pos - $pos - 1;
$words = explode('|', substr($input, $pos + 1, $diff));
$word_num = mt_rand(1, count($words)) -1;
$pos = strpos($input, '{', $pos+1);
$output .= $words[$word_num];
if ($pos)
{
$output .= substr($input, $close_pos + 1, ($pos - $close_pos - 1));
}
}
$output .= substr($input, $close_pos +1 );
return $output;
}
$input = file_get_contents('input.txt');
echo get_spin($input);
echo '<br/>';
echo get_spin($input);
?>
Sample input: I am a {little|small|tiny|big fat}, {lovely|nice|horrible|smelly} {cow|bovine|bull} and I {say|shout} {moo|moo moo moo} to you!
Hope someone gets some use from it
