Letters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Silver_Eclipse
Forum Commoner
Posts: 61
Joined: Sun Aug 18, 2002 7:26 pm

Post by Silver_Eclipse »

where did $ln come from? i understand that script u sent me now except for the $ln i know $ln_gt and $ln_lt are specified but where did just $ln come from?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

<?php 
$if_name = "file.ext"; // inputfile_name
$of_name = "char.txt"; // outputfile_name

if (file_exists($if_name)) 
&#123; 
   $f_contents = file($if_name);
   $fd_out = fopen($of_name, "a+"); // only appending !?
   $ln_gt = 62;  // linenumber_greaterthan 
   $ln_lt = 4320; // linenumber_lesserthan 

   // include 'style.css';  <- uncertain about this 
   // include 'header.php';  <- and that 

   for ($ln = $ln_gt+1; $ln < count($f_contents) && $ln < $ln_lt; $ln++) 
   &#123;
      fputs($fd_out, $f_contents&#1111;$ln]); 
      // you still can print it out now directly 
      // print($f_contents&#1111;$ln]);
   &#125;
   fputs($fd_out, "</table>");
   fclose($fd_out);
  
   /* if you want to read it back now - but just as reminder:
      the data is already available ;)
  */
  $f_contents = file($of_name);
&#125; 
else 
   printf('file not found: '.$if_name); 
?>
p.s.: $ln is defined and set before the loop-body of "for" is executed the first time ($ln = $ln_gt+1)

take a look at the for manual page
Silver_Eclipse
Forum Commoner
Posts: 61
Joined: Sun Aug 18, 2002 7:26 pm

Post by Silver_Eclipse »

thnx
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

poooh....finished.
As mentioned somewhere else here:
This is either my
"I will never be a teacher" day,
"I'm not a teacher" week or
"can't express anything" month

sorry 8O
Silver_Eclipse
Forum Commoner
Posts: 61
Joined: Sun Aug 18, 2002 7:26 pm

Post by Silver_Eclipse »

lol np i understand most of it
Silver_Eclipse
Forum Commoner
Posts: 61
Joined: Sun Aug 18, 2002 7:26 pm

Post by Silver_Eclipse »

$f_contents = file($of_name); looks like you are setting it to something and not reading it back?
fputs($fd_out, "</table>");
fclose($fd_out);

/* if you want to read it back now - but just as reminder:
the data is already available ;)
*/
$f_contents = file($of_name);
}
Silver_Eclipse
Forum Commoner
Posts: 61
Joined: Sun Aug 18, 2002 7:26 pm

Post by Silver_Eclipse »

oh yeah and the input files go with the read back part because one is a css style sheet for colors and stuff and the other is a graphic at the top of the page.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

file() reads the file and returns the contents line by line in an array.

But -doh- I'm an idiot. Your while-loop is correct, since
while(list($array) = each($file))
will make $array contain the index of the current array-element in each iteration :(

Right after I will have pressed "submit" I'll shutdown my computer and burry my head under a pillow (that will soften the hits I'll give myself)
Post Reply