Tell me, please, the script for writing to the file from a new line is the file "file.txt" and the text field "info".

    3 answers 3

    $fp = fopen('file.txt', 'a'); fwrite($fp, $_POST['info'] . PHP_EOL); fclose($fp); 
    • four
      PHP has constant PHP_EOL to indicate end of line - dekameron
    • @dekameron There is, but if the script runs on the linux server, it has "\ n" and if you read the file on Windows, you need "\ r \ n" - Naumov

    Hello @ cas-live . Add to the end of each line added \ r \ n

       $fp = fopen('file.txt', 'a+'); - а+ добавляет новые данные после существующих fwrite($fp, $_POST['info']."\r\n"); а "r\n\" - вставляет их каждый рас с новой строки fclose($fp); 

      That's what it should look like!

      Quote

      I implemented the code like this

       <?php if(isset($_POST['dosave'])){ $res=$_POST['res']; $filt = $_POST['file']; $filo = $_POST['filo']; $fito = $_POST['fito']; $fino = $_POST['fino']; $fitto = $_POST['fitto']; } ?> <?php echo $fino; ?> <?php echo $filt, $fitto; ?> <?php echo $fito; ?> <?php echo $filo; ?> <?php echo date ( ' j FY ' ) ; ?> <?php $opis = $fino. ' ' .$filt. ' ' .$fitto. ' ' .$fito. ' ' .$filo; $s = fopen("file.txt","a+"); fwrite($s,$opis."\r\n"); fclose($s); ?> 
      • each time the advanced data from the form is entered into a new line. And at the same time all the data from the form are combined in one line. - sobchenyuk 2:58 pm
      • Problem solved, but thanks - cas