FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a 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);
?>
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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