Может быть попробовать что-то вроде:
$content = "{hey|hi|hello there}! {i am|i'm} {good|great}!";
$randomOutput = preg_replace('/(\{.*?\})/s', function($matches) {
$possibilities = (array) explode('|', trim($matches[0], '{}'));
return $possibilities[array_rand($possibilities)];
}, $content);
Версия для PHP <5.3 </p>
function randomOutputCallback($matches) {
$possibilities = (array) explode('|', trim($matches[0], '{}'));
return $possibilities[array_rand($possibilities)];
}
$content = "{hey|hi|hello there}! {i am|i'm} {good|great}!";
$randomOutput = preg_replace('/(\{.*?\})/s', 'randomOutputCallback', $content);