OK, I have a page with a text field. You type into the text field. It saves as a txt file. Then another page includes the txt file as content. It works great apart from it ignores line returns typed in by the user.
I find code VERY hard to follow so it would be great if someone could just tell me exactly where and how to add code to make PHP save and read line breaks. I've asked questions before and got some very helpful answers. Only problem is that I'm clueless how to implement them! Please show me exactly where and how to put in the additional code... please!!! Being able to convert line returns to <br> tags on save so they appear in the txt file would be great. Here's the code I'm using:
<?php
$saving = $_REQUEST['saving'];
if ($saving == 1) {
$data = $_POST['data'];
$file = "text_files/a1txt.txt";
echo "\r\n";
$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!");
fclose($fp);
echo "Saved to $file successfully!";
}
?>
</p>
<form name="form1" method="post" action="a1txt.php?saving=1">
<textarea name="data" cols="70" rows="10">
<?php
$file = "text_files/a1txt.txt";
if (!empty($file)) {
$file = file_get_contents("$file");
echo $file;
}
?>
</textarea>
<br>
<input type="submit" value="Save">
</form>
I find code VERY hard to follow so it would be great if someone could just tell me exactly where and how to add code to make PHP save and read line breaks. I've asked questions before and got some very helpful answers. Only problem is that I'm clueless how to implement them! Please show me exactly where and how to put in the additional code... please!!! Being able to convert line returns to <br> tags on save so they appear in the txt file would be great. Here's the code I'm using:
<?php
$saving = $_REQUEST['saving'];
if ($saving == 1) {
$data = $_POST['data'];
$file = "text_files/a1txt.txt";
echo "\r\n";
$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!");
fclose($fp);
echo "Saved to $file successfully!";
}
?>
</p>
<form name="form1" method="post" action="a1txt.php?saving=1">
<textarea name="data" cols="70" rows="10">
<?php
$file = "text_files/a1txt.txt";
if (!empty($file)) {
$file = file_get_contents("$file");
echo $file;
}
?>
</textarea>
<br>
<input type="submit" value="Save">
</form>