<!-- Date: 2011-06-17 --> </head> <body> <?php function makeTrigram($str) { $tgram = array(); $words = explode(" ", $str); for ($i = 0; $i < count($words) - 2; $i++) { $tgram = concat1($words, $i, $i + 3); } return $tgram; } function concat1($word, $start, $end) { $stack = array(); for ($i = $start; $i < $end; $i++) { array_push($stack, $word[$i]); echo " "; } echo implode(" ", $stack); } $file_content = file_get_contents('story.txt'); $trigram = makeTrigram($file_content); for ($i = 0; $i < count($trigram) - 2; $i++) { echo $trigram[$i]; } ?> </body> </html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Ngram</title> </head> <body> <?php $file_input = file_get_contents('filename.txt'); while (!feof($file_input)) { $words = explode(" ", $file_input); } $ngram = makeTrigram($file_input); function makeTrigram($str) { $tg = array(); for ($i = 0; $i < count($words) - 2; $i++) { $tgram = concaten($words, $i, $i + 3); } return $tg; } function concaten($word, $start, $end) { $stack = array(); for ($i = $start; $i < $end; $i++) { array_push($stack, $word[$i]); echo " "; }