Function for getting random word from words in brackets


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.

Leave a Reply

Your email address will not be published. Required fields are marked *