(Lorem ipsum)
dolor sit amet,
(consectetur adipiscing elit, (sed do eiusmod))
\((.+)\)
preg_split("/\((.*?)\)/", $this->text, -1, PREG_SPLIT_DELIM_CAPTURE);
$rand_sentence = "{Please|Just} make this {cool|awesome|random} test sentence {rotate {quickly|fast} and random|spin and be random}";
$regexp = '#\{((?>[^{}]+)*)\}#';
while(strpos($rand_sentence, '{') !== false)
$rand_sentence = preg_replace_callback($regexp, 'replace_match_str', $rand_sentence);
echo $rand_sentence . "\n";
function replace_match_str($str)
{
$result = explode("|", $str[1]); // split string by "|" symbol
$replacement = array_rand($result); // random array ellement
return $result[$replacement];
}