Count messages to file

Hello, help with counting posts. Plan: the user adds a message, it is written to a file and output, and also the number of messages needs to be written to another file. Once => 1, the second added – 2. This is how I add an entry:

if (@$_POST['submit']) {
    $letters = letters . dat;
    $message = $_POST['message'];
    $message = htmlspecialchars($message);
    $message = ereg_replace("\n", "<br>", $message);
    $fh      = fopen($letters, "a");
    $str     = $mylogin . ":::" . $myphoto . ":::" . $message . ":::" . date('H:m') . "\r\n";
    fputs($fh, $str);

Answer 1, authority 100%

Add a couple more lines to your code (after closing the message file):

  1. Opening a file with the number of messages
  2. Reading a line from a file into a variable
  3. Increment variable by 1
  4. Rewrite this variable in the file with quantity
  5. Close the file with the number of messages