FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP: Writing to txt file





dynamics
I need help with this code:

Code:
<?php
$fh = fopen("mail.txt", "w");
$message = "";
foreach ($_POST as $field => $value)
{
fwrite($fh,"$field = $value\n");
}

fclose($fh);
?>


This code is supposed to get all values from the $_POST array and write them to a file called "mail.txt".

But, I am unable to leave a line after the fwrite method is carried out. In other words, the \n next line command seems not working at all. Hope you guys here can help.
Ducksteina
Try this:

Code:
<?PHP
   $fh = fopen("mail.txt", "w");
   $message = "";
   foreach ($_POST as $field => $value) {
      fwrite($fh, $field . '=' . $value . "\n");
   }
   fclose($fh);
?>
kv
Replace
Code:

fwrite($fh,"$field = $value\n");


with

Code:

fwrite($fh,"$field = $value \r\n");


It should solve the problem.
dynamics
Thanks guys! A little modification to my script works:

Code:
<?php
$fh = fopen("mail.txt", "w");
$message = "";
foreach ($_POST as $field => $value)
{
fwrite($fh,"$field = $value\r\n");
}
fclose($fh);
?>
Related topics
PHP & Chat
users online, using php and text file
PHP function(); &file=""?
Create a txt file
Creating a .txt file
.txt file to .php Lined to tables
Open, Write to and Close a txt file using php
does someone have a simple "save to txt file" scri
Displaying .txt file on web page
I can't open directly .txt file on my desktop
Saving a .txt file to a ftp using vb6. i need help please
VB 6.0 need help loading a .txt file into a text box
is it possible to get a html text box to load a .txt file?
Using php to change content of a .txt
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.