I have a form which sends data to a text file, but I’m trying to keep all data sent in the first line of that text file, and replacing would-be breaks with the br tags inside the text file itself. Sorry if there’s a really easy solution, but I’ve been searching and testing for over an hour now >_< (php newbie)
Edit: Yeah here’s the general gist of what I currently have. I’m using variables for it.
I have a form with one of the inputs named content that sends data to a submit.php.
In submit.php…
$content = $_POST['content'];
and that sends the following to a text file
$data = "$content";
$fh = fopen("file.txt", "a");
fwrite($fh, $data);
Look at the php function
nl2br()(php.net). It does exactly what you need, by going through the string you give it and replacing new lines (\ns and\rs) with<br/>tags.Apparently
nl2brdoesn’t remove the actual breaks, and only adds the br tags, so try this function: