Jump to content


Photo

FILES doubt


  • Please log in to reply
3 replies to this topic

#1 Gurzi

Gurzi
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 03 August 2006 - 01:25 AM

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


#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 03 August 2006 - 01:30 AM

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
Tell me the problem, I will try tell you the solution

#3 Gurzi

Gurzi
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 03 August 2006 - 02:10 AM

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



#4 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 03 August 2006 - 02:15 AM

\r is return
\n is new line
\t is tab
as txtpad is a plane text editor is uses \r not \n i guess
Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users