Find the answer to your Linux question:
Results 1 to 2 of 2
Whats wrong with this code Code: <html> <body> <?php $file = fopen("test.txt","a"); echo fwrite($file,$_POST["name"] . "<br />"); echo fwrite($file,$_POST["age"] . "<br />"); fclose($file); ?> </body> </html> its not skipping a ...
  1. #1
    Just Joined!
    Join Date
    Aug 2005
    Posts
    54

    PHP: Skipping Lines

    Whats wrong with this code
    Code:
    <html>
    <body>
    <?php
    $file = fopen("test.txt","a");
    echo fwrite($file,$_POST["name"] . "<br />");
    echo fwrite($file,$_POST["age"] . "<br />");
    fclose($file);
    
    ?>
    </body>
    </html>
    its not skipping a line....
    its like nameagenameage

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    You mean in text.txt?

    This is correct behavior. test.txt should look like:
    Code:
    Alex<br />19<br />
    The reason for this is that fwrite() simply writes the given string to the given file. It differentiates lines by using the newline character "\n", not the HTML line break.

    Try replacing the "<br />" with "\n".

    Having said all that, the example you've given makes little sense. Since fwrite() just returns the number of bytes written, you're going to end up with a page that just has two numbers on it.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

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