Results 1 to 8 of 8

Thread: Best way to print a new line to a txt file ?

  1. #1

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Best way to print a new line to a txt file ?

    I have this, and want to add a new line after each entry, ...?

    PHP Code:
    <?php
             
    $val 
    $_GET['data']; 

    $myFile "testFile.txt";
    $fh fopen($myFile'a') or die("can't open file");

    $stringData $val;
    fwrite($fh$stringData);
              

    fclose($fh); 
    ?>

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Best way to print a new line to a txt file ?

    What does an entry look like? Ie: how would you know where to add a new line?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: Best way to print a new line to a txt file ?

    whoops sry, i meant after the,

    PHP Code:
    fwrite($fh$stringData); 
    I tried a few variations such as,

    PHP Code:
    fwrite($fh$stringData); 
    fwrite($fh"\n"); 
    and

    PHP Code:
    fwrite($fh$stringData "\n"); 
    and

    PHP Code:
    fwrite($fh"$stringData\n"); 
    no joy though..

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Best way to print a new line to a txt file ?

    In HTML a line break is "<br />".
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: Best way to print a new line to a txt file ?

    Still can't get this simple thing working, i am taking in a query string and printing it to a text file,

    PHP Code:
    <?php
       
    $myFile 
    "testFile.txt";
    $fh fopen($myFile'a') or die("can't open file");
    $ref $_GET['data']; 
          
    $newline "<br />";

     
    fwrite($fh,$ref.$newline);
     
    fclose($fh); 

    ?>
    So the text file should look like

    string1
    string2
    string3

    but the above doesn't give that....

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Best way to print a new line to a txt file ?

    If your file is on a windows computer, you need to use "\r\n" for newlines, if it is on a mac then you should use just "\r".
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: Best way to print a new line to a txt file ?

    Let me try this another way.

    I want to append the incoming data to a text file, at the moment, the data is following on after each other on the same line with a newline character inbetween.

    so if i send
    .php?name= bill then
    .php?name= john then
    .php?name= fred

    then i want that saved to a text file like

    bill
    john
    fred

    at the moment its saving as

    bill john fred the spaces being newline characters.

  8. #8
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Best way to print a new line to a txt file ?

    Are you using Window or Linux, did you try \r\n.

    Forget <br />, I thought you were trying to display newlines in an HTML document.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width