How to write string in a file to the next line

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • marslee@hotmail.com

    #1

    How to write string in a file to the next line

    How to write data in a file to the next line

    fwrite($ourFile Handle , $_POST[user]);
    fwrite($ourFile Handle , "\n");
    fwrite($ourFile Handle , $_POST[address]);

    I want the following output

    Peter
    Main.st

    How can i do that?
    I tried many time,but Peter and main.st are on the same line.

  • Janwillem Borleffs

    #2
    Re: How to write string in a file to the next line

    marslee@hotmail .com wrote:[color=blue]
    > How to write data in a file to the next line
    >
    > fwrite($ourFile Handle , $_POST[user]);
    > fwrite($ourFile Handle , "\n");
    > fwrite($ourFile Handle , $_POST[address]);
    >
    > I want the following output
    >
    > Peter
    > Main.st
    >
    > How can i do that?
    > I tried many time,but Peter and main.st are on the same line.
    >[/color]

    \n only shows up in your browser when enclosed with <pre> tags.

    Look at the source directly, use <pre> tags or use <br> instead of \n



    JW

    Comment

    • Good Man

      #3
      Re: How to write string in a file to the next line

      marslee@hotmail .com wrote in news:1115044776 .207438.318080
      @o13g2000cwo.go oglegroups.com:
      [color=blue]
      > How to write data in a file to the next line
      >
      > fwrite($ourFile Handle , $_POST[user]);
      > fwrite($ourFile Handle , "\n");
      > fwrite($ourFile Handle , $_POST[address]);
      >
      > I want the following output
      >
      > Peter
      > Main.st
      >
      > How can i do that?
      > I tried many time,but Peter and main.st are on the same line.[/color]

      $user = trim($_POST['user']);
      $add = trim($_POST['address']);

      fwrite($ourFile Handle, "$user\n$ad d");



      Comment

      • Good Man

        #4
        Re: How to write string in a file to the next line

        Good Man <heyho@letsgo.c om> wrote in news:Xns964A75D AB70FEsonicyout h@
        216.196.97.131:
        [color=blue]
        > marslee@hotmail .com wrote in news:1115044776 .207438.318080
        > @o13g2000cwo.go oglegroups.com:
        >[color=green]
        >> How to write data in a file to the next line
        >>
        >> fwrite($ourFile Handle , $_POST[user]);
        >> fwrite($ourFile Handle , "\n");
        >> fwrite($ourFile Handle , $_POST[address]);
        >>
        >> I want the following output
        >>
        >> Peter
        >> Main.st
        >>
        >> How can i do that?
        >> I tried many time,but Peter and main.st are on the same line.[/color]
        >
        > $user = trim($_POST['user']);
        > $add = trim($_POST['address']);
        >
        > fwrite($ourFile Handle, "$user\n$ad d");[/color]

        (assuming you were writing to a text file)

        Comment

        • Chung Leong

          #5
          Re: How to write string in a file to the next line

          On Windows you need \r\n to produce a newline. Most editor is smart
          enough to recognize \n, but not Notepad. You used to be able to open a
          file in text mode, which turns on automatic translation of \n to \r\n.
          But the PHP devs now are discouraging its use and, the last time I
          tried, it didn't work.

          Comment

          Working...