<?php
//http://www.tizag.com/phpT/php-string-explode.php
//read text per line and convert to array

//for example, the input file is readtextperline.txt
//the input file contains text below

//++++++++++++++++++++++++++

//read value per line

$data = file_get_contents("readtextperline.txt"); //read the file
$convert = explode(" ", $data); //create array separate by new line
echo "Line count: " . count($convert) . "<br />";

for ($i=0;$i<count($convert);$i++)
{
echo $convert[$i] . "<br />"; //write value by index and add carriage return.
}

//Output specified number of records in this next example.
$convert1 = explode("\n", $data,5); //Using the third (optional) argument which allows you to set the number of pieces explode can return. This means it will stop exploding once the number of pieces equals the set limit.
echo "Line count: " . count($convert1) . "<br />";

for ($i=0;$i<count($convert1);$i++)
{ //echo "<pre>" . print_r($convert1) . "</pre>";
$x=$i+1;
echo "<b>" . $x . ": " . $convert1[$i] . " -----</b><br />"; //write value by index and add carriage return.
//Can apply different formatting to the selected 5 records. (Top 5 finishers in a race etc.)
}

//++++++++++++++++++++++++++

?>
Line count: 21
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
twenty

Line count: 5
1: one -----
2: two -----
3: three -----
4: four -----
5: five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty -----