Jump to content

Archived

This topic is now archived and is closed to further replies.

Gurzi

FILES doubt

Recommended Posts

Hy there...

I have one question about managing files..

I have one form with 2 input type="text" and i want to write the $_POST data on the file..

Ok, it works, but my problem is i want that the next registration be on a new line, so, when i open te agenda.txt(agenda is adress book in Portuguese, btw  ;D) the data is written on a new line...
I wrote the "\n" but i a single char appears on the .txt and the new registration occurs next the last one , instead of a new line

the code is :
if(isset($_POST['Adicionar']))
{
$handle = @fopen($file, "a+")
OR die("Failed to open the file " . $file . "\n");
    $nome = $_POST['Nome'];
$email = $_POST['Email'];


@fwrite($handle, $nome . "|-|");
@fwrite($handle,$email );
@fwrite($handle, "\n");

}

thnks a lot

Share this post


Link to post
Share on other sites
is the char a little box
Its something to do with encoding. Plain text does not read \n
open it in a rich text editor (Word, Dreamweaver ...) and it will be on a new line

Share this post


Link to post
Share on other sites
ok, i didn't know that point...

i tryed a different way, and it's fine.. but i dont understand why.. because i think that is the same thing :

$handle = @fopen($file, "ab+")  OR die("Failed to open the file " . $file);
    $nome = $_POST['Nome'];
$email = $_POST['Email'];

    $gravar = $nome  ."|-|". $email;
@fwrite($handle, "$gravar\r\n");

and now, the file jump to the next line

Share this post


Link to post
Share on other sites
\r is return
\n is new line
\t is tab
as txtpad is a plane text editor is uses \r not \n i guess

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.