On Fri, 20 Jul 2001 16:36, Er Galvão Abbott wrote:
> Greetings.
>
> First of all I'm a PHP bginner so take it easy on me :)
>
> I'm trying to make a script that does the following:
>
> * open a text file
> * read its contents
> * For each line on the file make a input tag with its contents, like
> <input type="text" name="line1" value="foo is what we use to ask
> questions. It doesn't really mean something.">
> * Take the modified contents - modifyied in the input fields - and
> update the text file
>
> So, I've begun with:
>
> 1 <?php
> 2 $file = "news.txt";
> 3 fopen ($file, "r");
> 4 $fs = filesize ($file);
> 5 while (!feof($file))
> 6 {
> 7    $content = (fgets ($file, $fs));
> 8 }
> 9 ?>
>
> One thing I didn't understood is the length part of the fgets
> command... Why use length with it? So, what I'm trying to do in lines
> 4 and 7 is to make sure it gets the contents by setting length = file
> size... Am I right on this?
>
> How do I split the contents of the file? Because I'm getting the
> content of both lines in the $content variable...
>
> I'm originally a Perl programmer so I know that the "split mark" must
> be the end of line, but I'm really lost here.
>
> Can someone help me?
>
> Thanks in advance,

Heh. File handling must be a bit different in Perl :-) Your code above 
doesn't use the file descriptor (or file handle, if you prefer, or file 
pointer) that is returned by the fopen function.

1 <?php
2 $file = "news.txt";
3 $fp = fopen ($file, "r");
4 $fs = filesize ($file);
5 while (!feof($fp))
6 {
7    $content = (fgets ($fp, $fs));
8 }
9 ?>

However, you might be as well off to use the file() function to read the 
file into an array; you can then process the array with list/each and 
write it out line by line.

-- 
David Robley      Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES      Flinders University, SOUTH AUSTRALIA  

   I failed attitude in school.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to