File Function (returning multiple lines from a file)
Posted: Tue May 20, 2003 3:16 pm
How can I make the following code return more then one line from the file read in? right now it will only return the first line from the file and thats it
<?php
function getFile( $FN )
{
if(!file_exists($FN))
{
echo 'Bad file name';
return;
}
$fp = fopen ($FN, "r");
while($line = fgets($fp, 1024))
{
list($project_number,$workpackage_number,$employee_number,$date,$number_of_hours)= explode(",",$line);
$oneline = array($project_number,$workpackage_number,$employee_number,$date,$number_of_hours);
return $oneline;
}
fclose($fp);
}
$man = array();
$man = getFile("timerecords.txt");
for($i = 0; $i < count($man); $i++)
{
echo $man[$i];
}
?>
<?php
function getFile( $FN )
{
if(!file_exists($FN))
{
echo 'Bad file name';
return;
}
$fp = fopen ($FN, "r");
while($line = fgets($fp, 1024))
{
list($project_number,$workpackage_number,$employee_number,$date,$number_of_hours)= explode(",",$line);
$oneline = array($project_number,$workpackage_number,$employee_number,$date,$number_of_hours);
return $oneline;
}
fclose($fp);
}
$man = array();
$man = getFile("timerecords.txt");
for($i = 0; $i < count($man); $i++)
{
echo $man[$i];
}
?>