function randomWords($paragraph){ //get one from the words in {} |
|
preg_match_all('/{(.*?)}/s', $paragraph, $matches); |
|
foreach($matches[1] as $variations){ |
|
$variations_array = explode('|',$variations); |
|
$paragraph = str_ireplace('{'.$variations.'}',$variations_array[array_rand($variations_array)],$paragraph); |
|
} |
|
return $paragraph; |
|
} |
For example {traces | trails | spots}. Will return one of the words in brackets.