function get_first_words() {
$firstWords = array();
$file = file("data.txt");
foreach ($file as $line) {
if (trim($line) != '') {
$expl = explode(" ", $line);
$firstWords[] = $expl[0];
}
}
return $firstWords;
}
echo implode(', ', get_first_words());
/*
run:
PHP, that, It, Rasmus, PHP
*/