I would like to split a txt file that i use as a log in a comment system after each 10 comments how can i do that? Here is my code, Sorry for the bad indentation:

<?php
$act = $_POST['act'];
if ($act == "post")
 {
   $name = $_POST['name'];
   $area = $_POST['area'];
   @$fp = fopen($file, 'a');
   if (!$fp)
    {
      //The file could not be opened
      echo "";
    }
   else
    {
      //The file was successfully opened, lets write the comment to it.
      date_default_timezone_set('Europe/London');
      setlocale(LC_ALL, "en_GB");
      $area       = stripslashes(htmlspecialchars($area));
      $txtSmileys = array(
         ':)',
         ':(',
         ':d',
         '-_-',
         ';)',
         'o.O',
         '^^'
      );
      $imgSmileys = array(
         htmlspecialchars_decode('<img src="/emoticons/smile.gif" alt=":)" />'),
         htmlspecialchars_decode('<img src="/emoticons/sad.gif" alt=":("/>'),
         htmlspecialchars_decode('<img src="/emoticons/laugh.gif" alt=":d"/>'),
         htmlspecialchars_decode('<img src="/emoticons/mellow.gif" alt="-_-"/>'),
         htmlspecialchars_decode('<img src="/emoticons/wink.gif" alt=";)"/>'),
         htmlspecialchars_decode('<img src="/emoticons/ohmy.gif" alt="o.O"/>'),
         htmlspecialchars_decode('<img src="/emoticons/smile.gif" alt="^^"/>')
      );
      $area       = str_ireplace($txtSmileys, $imgSmileys, $area);
      $area       = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\" target=\"_blank\" rel=\"nofollow\">\\0</a>", $area);
      $area       = wordwrap($area, 62, "\n", true);
      if (($area != "") && ($name != "") && ($name != "sanch"))
       {
         $outputstring = "<div id=shadow><b>" . stripslashes(htmlspecialchars($name)) . " </b> on the " . strftime('%d/%m/%y') . " at " . strftime('%H:%M') . " GMT wrote:<div id=line></div> <div id=br>" . ($area) . "</div></div>

";
       }

      //Write to the file
      fwrite($fp, $outputstring, strlen($outputstring));
      //We are finished writing, close the file for security / memory management purposes
      fclose($fp);
      //Post the success message
      header('Location: ');
    }
 }
else
 {
   //We are not trying to post a comment, show the form.
?>
<div id ="toptext">Comments:</div>
<div id="scroll">
<?php
   if ('' == file_get_contents($file))
    {
      echo '<div id="shadow">Nobody has commented yet. Be the first? </div>';
    }
   else
    {
      include($file);
    }
?>
</div>



<div id="form" class="top effect2" >
<p>Post a comment:</p>


<form action="<?php echo $self; ?>" name="form" method="post">




          <input type="text" class="text" name="name" value="anonymous"></input>
<div id="yo"></div>          
<textarea name="area" id="area" class="textbox" wrap="no"></textarea>   


<a href="#" class="grad" onclick="document.form.submit(); this.blur(); ">Submit</a>

<input type="hidden" name="act" value="post"></input>
</form>

</p>
</div>



<?php
 }
?>
Member Avatar for iamthwee

Set up a counter, when it reaches ten (for the comments) open another file to write to.

append a number onto that file name... So it might go from 1-100, or whatever.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.