[Pugged] Coding Questions

Renegade Muskrat ciapug@ciapug.org
Tue, 04 Mar 2003 17:30:36 -0600


In the interests of efficiency, could you just read the first line outside
of the loop and discard it rather than using a counter? Something like this
perhaps:

$handle = fopen ("/tmp/inputfile.txt", "r+");
fgets($handle, 4096);
$newbody = "";
while (!feof ($handle)) {
    $newbody .= fgets($handle, 4096);
}
fputs($handle,$newbody);
fclose ($handle);

If that ends up using too much memory, you could use a temp file, move the
fputs into the loop and have it write to the temp file, and after the loop
rename the temp file to the original.

At 03:39 PM 3/4/2003 -0600, you wrote:
>OOPS, don't know if that last email went thru..but i wasn't read to send
>it, i'll try again:
>
>$handle = fopen ("/tmp/inputfile.txt", "r+");
>$i = 0;
>$newbody = "";
>while (!feof ($handle)) {
>    $buffer = fgets($handle, 4096);
>    if($i > 0){
>      $newbody .= $buffer;
>    }
>    $i++;
>}
>fputs($handle,$newbody);
>fclose ($handle);
                                               -- Dan
  --------------------------------------------------------------------
            "I'm still sane on three planets and two moons."
  --------------------------------------------------------------------
      Daniel Ramaley                  3118 Cottage Grove Ave Apt 8
      dramaley at spatulacity dot cx        Des Moines, Iowa 50311
      http://www.spatulacity.cx/                    (515) 271-5233
  --------------------------------------------------------------------
       WARNING: REDISTRIBUTION OF THIS MESSAGE MAY BE IN
                VIOLATION OF APPLICABLE COPYRIGHT LAWS.
                THIS MESSAGE NOT GUARANTEED Y-TO-K COMPLIANT.