So here is my final test code, notice the check for ' ' in the if.

Since I'm on Linux, this has to do with whats between the last LF and EOF which is nothing but this nothing will get printed out.

$file = fopen("somefile.txt", "r");
while (! feof($file))
        {
        $names = trim(fgets($file));
        if ($names == '')
                {
                break;
                }
        print $names."sometext\n";
        }
fclose($file);


- aurf

On Nov 24, 2009, at 5:52 PM, ryan wrote:

Is this what you want

$file = fopen("test.txt", "r");
while (!feof($file)) {
  $line = trim(fgets($file));
  print $line."sometext\n";
  }
fclose($file);

outputs
asometext
bsometext
csometext

Ref to http://us3.php.net/manual/en/function.fgets.php. "Reading ends when /length/ - 1 bytes have been read, on a newline (which is included in the return value), or on EOF (whichever comes first). If no length is specified, it will keep reading from the stream until it reaches the end of the line. "


aurfal...@gmail.com wrote:
Hi all,

I'm trying to append some text to what I read from a file.

My code;

$file = fopen("foo.txt", "r");
while (!feof($file)) {
   $line = fgets($file);
   print $line."sometext";
   }
fclose($file);

foo,txt;
a
b
c
d
e
f
g

And when I run the script, it looks like;
a
sometextb
sometextc
sometextd
...


Any ideas?

Thanks in advance,
- aurf




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to