Tx, man.

You helped a lot here, but now I'm having some problems updating the
text file.

I've made some changes in the code myself, so here it is:

The reading process is made by this:

<?php
clearstatcache ();
$file = "/usr/local/.../news.txt";
$abrir = fopen ($file, "r");
$i = 1;
 while($buffer = fgets($abrir, 18976) )
 {
  print "<input type='text' name='line[$i]' size='60' value='" .
$buffer ."'><br>";
  $i++;
 }
fclose($abrir);
?>

This is working great, thanks to you, but the writing script is
working with the second line only.... I think I'm really making a mess
here, so here it is:

<?php
$file = "/usr/local/.../news.txt";

while(list($var, $value) = each($HTTP_POST_VARS))
{
    for($x=1;$x<3;$x++)
/* I know I did a bad thing defining the limit (3) here, but I really
need this to work on URGENT basis so...*/
{
    echo "Updated: $value[$x]<br>";

$abrir = fopen($file, "w");
    fputs($abrir,$value[$x]."\n",strlen($value[$x]));
}
fclose($abrir);
    }
?>

The "echo" thing works great, but the writing process is messed up...
It only writes the second (last) line of text...

I know I'm being stupid somewhere, but I'm still having some trouble
understanding PHP syntax, so if you or anybody else can help me
again...

On Fri, 20 Jul 2001 03:41:14 -0700, [EMAIL PROTECTED] (Paul A.
Procacci) wrote:

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

       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