Search code examples
phphtmllinesubmitnewline

How to make a new line in a txt file when taking in data from a text file?


I'm trying to make the smallest possible chat I can in php and html. I have it set so any data sent from a input text box is sent to a file named data.txt. I then have iframed the data.txt like <iframe src="data.txt"></iframe> and to make it more viewable I have css

div, iframe {  
    width: 100%;  
    height: 100px;   
    margin: 0 auto; 
    background-color: #777;
}

Basically, the point is i would like it so each time the form is submitted and text is written into data.txt I would like for a new line to be made. I use this php:

if(isset($_POST['textdata1']))
{
$data=$_POST['textdata1'];
$fp = fopen('data.txt', 'a');
fwrite($fp, $data);
fclose($fp);
}

I tried to put a \n in a couple different spots but i just kept getting errors. Anyway, I know this was kind of long and it didn't have to be but I wanted to make sure you had all information needed. Thanks in advance!


Solution

  • I just had to put . "\n" in fwrite($fp, $data); but unfortunately after i asked a question on repl.it forums my school blocked repl.it so i can no longer code online. (I use my chromebook to code.)