rfresh
02-24-2009, 11:42 PM
I've been searching for this answer and I just can't get my head wrapped around some the posts that I have read.
I have a textarea with this text:
aaaa
bbbb
cccc
dddd
But when I write this data to a file it writes out like this:
aaaabbbbccccdddd
I've tried doing this but it doesn't work:
$php_string0 = str_replace("<br>","\n", $php_filedata);
Thanks for any help...!!!
CaptainB
02-25-2009, 08:17 AM
Hi there.
I don't know if it is for any help, but this is the script I'm using to post data from a form to a .txt file:
<?php
$saving = $_REQUEST['saving'];
if ($saving == 1){
$data = $_POST['data'];
$file = "auto_content/news.txt";
$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!";
}
?>
<form name="add_news" method="post" action="add_news.php?saving=1" >
<textarea name="data">
</textarea>
<input type="submit" value="Save">
</form>
Btw, wrong forum.
abduraooft
02-25-2009, 08:55 AM
But when I write this data to a file it writes out like this:
aaaabbbbccccdddd
Are you viewing the data directly from the file?
rfresh
02-25-2009, 04:54 PM
Are you viewing the data directly from the file?
Yes...
oesxyl
02-25-2009, 05:03 PM
Yes...
this is not because you replace \r\n with ''?
see that post:
http://www.codingforums.com/showpost.php?p=785875&postcount=4
the part about replacing with spaces not ''.
best regards
abduraooft
02-26-2009, 07:19 AM
Yes...
You could use nl2br() (http://php.net/nl2br) function to retain the line breaks while displaying the content on a page.
oesxyl
02-26-2009, 09:08 AM
You could use nl2br() (http://php.net/nl2br) function to retain the line breaks while displaying the content on a page.
this will not work because is no newlines in that file.
best regards