Thread: no eof ever?

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    2
    Rep Power
    0
    I'm trying to write to a file, then write the contents of that file into html. The recieving file "data.txt" is recieving one line of input, and the html prints infinitely (well, up to 175 k at which I pulled the plug) Here's the code.

    <html>
    <head>
    <title>write test</title>
    </head>
    <body bgcolor="green">
    <p>
    Here's some text in the html, later
    we'll see what comes from the php
    </p>

    <?
    // open file for writing
    $myFile = fopen("data.txt", "w");

    // make sure file opened
    if(!($myFile))
    {
    print("file open no can do boss");
    exit;
    }

    for($index=0; $index<10; $index++);
    {
    //write a line to file
    fputs($myFile, "line $index n");
    }

    while(!(feof($myFile)))
    {
    // read from the file
    //$myLine = fgetss($myFile, 255);
    //print("$myLine <br>n");
    print('Hell, say anything! ');
    }

    // close file
    fclose($myFile);
    ?>

    </body></html>

    --
    Robert Link
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Niteroi, RJ, Brazil
    Posts
    30
    Rep Power
    15
    Since you're always putting, it has no EOF.

    But if you're reading from somewhere else... Then check the EOF of the source file.

    ------------------
    Eduardo Teixeira Cardoso
    PHP Programmer from Brazil
    idnotfound@vircio.com.br
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Somewhere,in,UK
    Posts
    9
    Rep Power
    0
    for($index=0; $index<10; $index++);
    {
    //write a line to file
    fputs($myFile, "line $index n");
    }

    $myFile is still open when you get here, for writing. You need to close it before you do the next bit...

    eg.
    fclose($myFile);
    $myFile=fopen("data.txt","r");

    while(!(feof($myFile)))
    {
    // read from the file
    //$myLine = fgetss($myFile, 255);
    //print("$myLine <br>n");
    print('Hell, say anything! ');
    }

    // close file

    Hope that helps,

    Kelv



    ------------------
    ------------------------
    Kelv (29359814)
    http://www.lohost.com
    Low cost high uptime
    for your sites.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    2
    Rep Power
    0
    Kelv and Eduardo, thanks! Closing and reopening the file did the trick.
    --
    Robert Link

Similar Threads

  1. End Of Line (EOF) Problem
    By Ramihg in forum Visual Basic Programming
    Replies: 11
    Last Post: January 5th, 2004, 06:20 AM
  2. Recordset BOF & EOF both True thou' Recordset contains records
    By BanksySan in forum Visual Basic Programming
    Replies: 2
    Last Post: December 4th, 2003, 06:27 PM
  3. Replies: 4
    Last Post: October 14th, 2003, 07:20 PM
  4. send EOF down pipe to STDIN
    By infamous41md in forum C Programming
    Replies: 3
    Last Post: October 10th, 2003, 08:15 AM
  5. EOF error using News::NNTPClient
    By colpaarm in forum Perl Programming
    Replies: 7
    Last Post: December 29th, 2001, 11:25 AM

IMN logo majestic logo threadwatch logo seochat tools logo