<?php
function rand_wrd($input){
if (!is_array($input)){
return preg_replace_callback('~\{(.+?)\}~', 'rand_wrd', $input);
} else {
$input = explode("|", $input[1]);
return $input[array_rand($input)];
}
}
//the text file containing the sentences....
$file = file('textfilename.txt');
$file = array_map('rand_wrd', $file);
//display a random sentence...
echo $file[array_rand($file)];
?>