The fgets length is like this:  It's the number of bytes read from a
file OR up to a new line character.  Which ever comes first.  It's as
simple as that.  

Try this:

<?

$file = "filename.txt"; // Name of file

$fp = fopen($file, "r");

if(!$fp){
 echo "Couldn't open file for reading.";
}
else{
 $i = 1; // used for name of inputs
 while($buffer = fgets($fp, 18976) ){ //18796 is what I use.  Use a
larger number if your lines are larger.
  print "<input type='text' name='line[$i]' value='" . $buffer .
"'><br>";
  $i++;
 }
}

fclose($fp);

?>

That's what gets displayed to this user and this is how we would rewrite
the file:

<?

$file = "filename.txt";

$fp = fopen($file, "w");

if(!$fp){
 print "Couldn't open the file for writing";
}
else{
 for($x = 1; $x <= count($line); $x++){
  fputs($fp, $line[$x], strlen($line[$x]);
 }
}

fclose($fp);

?>

I hope this helps.

Paul


"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,
> 
>        Er Galvão Abbott
>          Webdeveloper
>   [EMAIL PROTECTED]
> ---------------------------------
> To send me an e-mail just remove
> the CAPITAL TEXT.
> ---------------------------------

-- 
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