Writing to a new line in a text file? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Writing to a new line in a text file?

SnookerLoopySnookerLoopy Posts: 41Member
Ello there, I was wondering if anyone can help me with this simple problem...

------------------------------------------------------------------


<?
$string = $_GET['entry'];
?>



<?

$filename = 'test.txt';
$fp = fopen($filename, "a+");
$write = fputs($fp, $string);
fclose($fp);

?>


------------------------------------------------------------------

It works okay, it basically adds whatever gets entered to the PHP script by the URL into the text file "test.txt", but it's all on the same line. I've tried using '
' and all that, but I can't get it to do what I want.

All I want to do is add each new entry to a new line in the text file.

Help!

Cheers :)

Comments

  • mac_doggiemac_doggie Posts: 488Member
    : Ello there, I was wondering if anyone can help me with this simple problem...
    :
    : ------------------------------------------------------------------
    :
    :
    : <?
    : $string = $_GET['entry'];
    : ?>
    :
    :
    :
    : <?
    :
    : $filename = 'test.txt';
    : $fp = fopen($filename, "a+");
    : $write = fputs($fp, $string);
    : fclose($fp);
    :
    : ?>
    :
    :
    : ------------------------------------------------------------------
    :
    : It works okay, it basically adds whatever gets entered to the PHP script by the URL into the text file "test.txt", but it's all on the same line. I've tried using '
    ' and all that, but I can't get it to do what I want.
    :
    : All I want to do is add each new entry to a new line in the text file.
    :
    : Help!
    :
    : Cheers :)
    :
    Hi,

    You should try to use



    is the carrier return command that brings back the cursos to the beginning of the line, and
    will move the cursor down 1 pos to a new line that is created.

    ;-)
    -mac-
    mailto:[email protected]
    the Netherlands...


  • SnookerLoopySnookerLoopy Posts: 41Member
    : : Ello there, I was wondering if anyone can help me with this simple problem...
    : :
    : : ------------------------------------------------------------------
    : :
    : :
    : : <?
    : : $string = $_GET['entry'];
    : : ?>
    : :
    : :
    : :
    : : <?
    : :
    : : $filename = 'test.txt';
    : : $fp = fopen($filename, "a+");
    : : $write = fputs($fp, $string);
    : : fclose($fp);
    : :
    : : ?>
    : :
    : :
    : : ------------------------------------------------------------------
    : :
    : : It works okay, it basically adds whatever gets entered to the PHP script by the URL into the text file "test.txt", but it's all on the same line. I've tried using '
    ' and all that, but I can't get it to do what I want.
    : :
    : : All I want to do is add each new entry to a new line in the text file.
    : :
    : : Help!
    : :
    : : Cheers :)
    : :
    : Hi,
    :
    : You should try to use

    :
    :
    is the carrier return command that brings back the cursos to the beginning of the line, and
    will move the cursor down 1 pos to a new line that is created.
    :
    : ;-)
    : -mac-
    : mailto:[email protected]
    : the Netherlands...
    :
    :
    :

    Thanks mac, where abouts do I put
    ? Could you show me in the code above, or should it be in the URL? Thanks.

    :)
  • Eraser9486Eraser9486 Posts: 32Member
    $write = fputs($fp, $string . "
    ");


    That should be sufficient for what you are attempting to do..

    : : : Ello there, I was wondering if anyone can help me with this simple problem...
    : : :
    : : : ------------------------------------------------------------------
    : : :
    : : :
    : : : <?
    : : : $string = $_GET['entry'];
    : : : ?>
    : : :
    : : :
    : : :
    : : : <?
    : : :
    : : : $filename = 'test.txt';
    : : : $fp = fopen($filename, "a+");
    : : : $write = fputs($fp, $string);
    : : : fclose($fp);
    : : :
    : : : ?>
    : : :
    : : :
    : : : ------------------------------------------------------------------
    : : :
    : : : It works okay, it basically adds whatever gets entered to the PHP script by the URL into the text file "test.txt", but it's all on the same line. I've tried using '
    ' and all that, but I can't get it to do what I want.
    : : :
    : : : All I want to do is add each new entry to a new line in the text file.
    : : :
    : : : Help!
    : : :
    : : : Cheers :)
    : : :
    : : Hi,
    : :
    : : You should try to use

    : :
    : :
    is the carrier return command that brings back the cursos to the beginning of the line, and
    will move the cursor down 1 pos to a new line that is created.
    : :
    : : ;-)
    : : -mac-
    : : mailto:[email protected]
    : : the Netherlands...
    : :
    : :
    : :
    :
    : Thanks mac, where abouts do I put
    ? Could you show me in the code above, or should it be in the URL? Thanks.
    :
    : :)
    :

  • SnookerLoopySnookerLoopy Posts: 41Member
    Thanks to both of you, it works now, cheers :-)
Sign In or Register to comment.