Why does feof hate me??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ChineseStunna
Forum Newbie
Posts: 2
Joined: Wed Jun 04, 2003 11:35 am

Why does feof hate me??

Post by ChineseStunna »

so I'm just trying to learn how to do some txt file parsing with php and here's what I've tried so far:

$handle = fopen("test.txt", "r+");
fwrite($handle,"This works", 1024);
fclose($handle);

and test.txt will have This works written into it.

but, since I need to parse and existing file, I have to read it into a buffer first:

$handle = fopen("mail.txt", "r");
while (!feof($handle))
{
$buffer = fread($handle, 4096);
}

this would cause a parse error in the $handle = fopen(...) line?! What the hell? I've been reading php.net's page on feof and fopen forever now and I can't figure out why that just won't wory and would tell me this:

Parse error: parse error, unexpected T_VARIABLE in /home/zeuspc/public_html/news/mailp.php on line 5

line5 being the $handle = fopen(...) line.

Thanks in advance :)

Stunna
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

The error message:
Parse error: parse error, unexpected T_VARIABLE in /home/zeuspc/public_html/news/mailp.php on line 5
indicates that there is something wrong above line 5 - what's on lines 1-4?

Mac
ChineseStunna
Forum Newbie
Posts: 2
Joined: Wed Jun 04, 2003 11:35 am

Post by ChineseStunna »

Err... LOL thanks, sorry left out a ; on 4 :P

Thank you very much
Post Reply