PDA

View Full Version : read from file problem


cntrybob
03-02-2003, 01:39 AM
Am working on a simple card script that reads and writes to a text file instead of a database ... can write to the file , but can't read from and get print to work ...see anything here?

function ReadFromFile () {
$TheFile = "card.txt";
$Open = fopen ($TheFile, "r");
if ($Open) {
print ("Your Birthday Wishes:
n");
$Data = file ($TheFile);
for ($n = 0; $n < count($Data);
$n++) {
$GetLine = explode("t",
$Data[$n]);
print ("$GetLine[0]
n$GetLine[1]

n");
}
fclose ($Open);
print ("<hr>
n");
} else {
print ("Unable to read from file!
n");
}
}

any print after this will print to the page, but nothing from the ReadFromFile is getting to the page ... not even Unable to read from file!

appreciate any help .. thanks

John
03-02-2003, 12:22 PM
Padon me for reformatting this, but it makes it easier to read.



function ReadFromFile ()

{

$TheFile = "card.txt";

$Open = fopen ($TheFile, "r");

if ($Open)

{

print ("Your Birthday Wishes:n");

$Data = file ($TheFile);

for ($n = 0; $n < count($Data); $n++)

{

$GetLine = explode("t", $Data[$n]);

print ("$GetLine[0]n$GetLine[1]<P>n");

}

fclose ($Open);

print ("<hr>n");

}

else

{

print ("Unable to read from file!n");

}

}

eugene
03-03-2003, 11:25 PM
cntrybob, is this still a problem? If so, private message me.
If not, please post to this board that your issue has been resolved.
-Eugene

cntrybob
03-04-2003, 01:29 PM
back to the drawin board on this one for me ... thanks, no responses please ..

Anonymous
03-05-2003, 05:14 PM
Did you try to echo the file contents without using explode just to make sure it's reading the file at all? Like..


$information = file ("card.txt");
echo $information[0];

That should output the first line of the file... and you could use the loop with the counter to reference the different lines.