I'm writing code for a class where I've set up functions to load data from a file in the same directory as the PHP file (using the "file" method). Then, the goal is for the program to take the info from that function and, 1) search for a match from user-inputted names, 2) replace the old name (scanned by the second function) with the new name, and 3) save it back to the original file. The file contains info that was input to it by another PHP page, but that really doesn't matter. The problem is that I wrote the following test code to retrieve the info from the file, but it's not working properly.
<?php
function loadData()
{
if(!$filename = file("employees .dat"))
{
echo('Error while opening file');
}
else
{
$numLines = count($filename );
for ($i = 0; $i < $numLines; $i++)
{
$filename[$i];
}
return array($filename );
}
}
$myFile = loadData();
echo($myFile);
?>
Again, this is just a test code. The ultimate aim is not to print the array to the screen, but to retrieve the data from the function so that it can be passed on to the next function that will scan the array to see if an input from the user matches an existing name in the file. I can post the rest of the code after I get this part working correctly.
P.S. The result of the function as it stands right now, is the word "Array" printed at the top left of the screen and nothing else. [It appears that it's returning the return TYPE instead of the actual values of the elements in the array]. Any help would be much appreciated, as all the other posts about similar issues seemed to be about databases, and not applicable. Thanks.
<?php
function loadData()
{
if(!$filename = file("employees .dat"))
{
echo('Error while opening file');
}
else
{
$numLines = count($filename );
for ($i = 0; $i < $numLines; $i++)
{
$filename[$i];
}
return array($filename );
}
}
$myFile = loadData();
echo($myFile);
?>
Again, this is just a test code. The ultimate aim is not to print the array to the screen, but to retrieve the data from the function so that it can be passed on to the next function that will scan the array to see if an input from the user matches an existing name in the file. I can post the rest of the code after I get this part working correctly.
P.S. The result of the function as it stands right now, is the word "Array" printed at the top left of the screen and nothing else. [It appears that it's returning the return TYPE instead of the actual values of the elements in the array]. Any help would be much appreciated, as all the other posts about similar issues seemed to be about databases, and not applicable. Thanks.
Comment