Creating a new line in a txt file

Discussion in 'PHP' started by FPForum, Aug 8, 2006.

  1. #1
    Hello everyone. My php script outputs some information into a text file and I am trying to have information put onto seperate lines
    for example:
    the text currently looks like this: firstname lastname city state
    I want it to look like this:
    firstname
    lastname
    city
    state

    i have tried using < /br> and ; at the end of my variables but doesnt seam to be working..any ideas?
     
    FPForum, Aug 8, 2006 IP
  2. Edynas

    Edynas Peon

    Messages:
    796
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try putting /n after the variables for the newline command. If it doesn't work could you post the code
     
    Edynas, Aug 8, 2006 IP
  3. hextraordinary

    hextraordinary Well-Known Member

    Messages:
    2,171
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    105
    #3
    "/n" should work you can also add "/r" for cartridge return just to be on the safe side.
     
    hextraordinary, Aug 8, 2006 IP
  4. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yah, putting "/n" (the newline character) should work - "<br>" is only understood by web browsers...
     
    daboss, Aug 8, 2006 IP
  5. zeljic

    zeljic Peon

    Messages:
    218
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    do not putting anything. just push ENTER.
     
    zeljic, Aug 8, 2006 IP
  6. skimmy

    skimmy Peon

    Messages:
    138
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I believe that you will need to put '\n' and not '/n'.
     
    skimmy, Aug 8, 2006 IP
  7. coderlinks

    coderlinks Peon

    Messages:
    282
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You use \n for *nix, \r\n for windows and \r for Mac. But I think \n by itself is often quite enough.

    Thomas
     
    coderlinks, Aug 8, 2006 IP
  8. Edynas

    Edynas Peon

    Messages:
    796
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #8
    My bad..it's indeed \n
     
    Edynas, Aug 8, 2006 IP
  9. Cryogenius

    Cryogenius Peon

    Messages:
    1,280
    Likes Received:
    118
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Note: '\n' (single quotes) won't work, so make sure you use "\n" (double quotes).
     
    Cryogenius, Aug 8, 2006 IP
  10. topwebserv

    topwebserv Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Change from </br> to >> <br /> if you print or echo for display on browser i think it can show.

    example

    your data // profile.txt

    //--------------------
    firstname<br/> lastname<br /> age<br/>

    you must split data for show again
     
    topwebserv, Aug 8, 2006 IP
  11. Gordaen

    Gordaen Peon

    Messages:
    277
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #11
    <?php
    $stuffToWrite = "$firstname\n";
    $stuffToWrite =. "$lastname\n";
    $stuffToWrite =. "$city\n";
    $stuffToWrite =. "$state\n";
    
    writeMyStuff($stuffToWrite);
    ?>
    
    PHP:
    Obviously replacing the function/variable names as appropriate
     
    Gordaen, Aug 8, 2006 IP
  12. coderlinks

    coderlinks Peon

    Messages:
    282
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Shouldn't that be
    
    $stuffToWrite .= "$lastname\n";
    
    PHP:
    ?

    Thomas
     
    coderlinks, Aug 8, 2006 IP
  13. Gordaen

    Gordaen Peon

    Messages:
    277
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Oops, good catch, you're right.
     
    Gordaen, Aug 9, 2006 IP