0

Hi,

Hope someone can help.

I have a form with several fields in it. One of the fields is a textarea. The user can enter data in this field, including carriage returns etc.,

Once the user clicks on SUBMIT I write the form contents to a text file.

When I read the file, I use FGETS. However the textarea field is now split up into multiple strings, which really messes up the presentation.

How do I keep the contents of the textarea as one BIG LONG string? So I understand I would need to use NL2BR to convert the blank lines with BR, I also have a short piece of code to remove any extra lines and also use TRIM to remove stuff from the end of each line.

But how to join it together and write it as one long string so that it can be read correctly?

Many thanks for any help!

Regards,

Mohamed

2
Contributors
1
Reply
5
Views
9 Years
Discussion Span
Last Post by nav33n
0
<?php //test.php
if(isset($_POST['submit'])){
	$area=$_REQUEST['area'];
	$fd=fopen("test.txt","w+");
	fwrite($fd,$area);
	fclose($fd);
	$file_contents=file_get_contents("test.txt");
	print $file_contents;
}
?>
<html>
<body>
<form method="post" action="test.php">
Enter something: <textarea cols=40 rows=10 name="area"></textarea><br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

file_get_contents reads the entire file into a string.
Cheers,
Naveen

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.