[thelist] preserving line breaks in a text file

Marianela Queme mqueme at gmail.com
Mon Jan 15 15:12:44 CST 2007


hi Mark

try:

fwrite($file,"$data\r\n");

see if that helps.

mq

On 1/15/07, Mark Mckee <lists at soddengecko.com> wrote:
>
> hi all
>
> this was previously known as "text file creation from user form" but i
> have since surpassed that and have what i need,
>
> i am however having some trouble preserving the line breaks. as the
> output of the file is just a plain text file, i do not need the nl2br
> function adding in some <br /> wherever a line break occurs. i have not
> been able to find anything on this that has helped
>
> anyone have any suggestions?
>
> here is the code i am using
>
> <?php
>    $guestbook = "files/$title.txt";
>    error_reporting (E_ALL ^ (E_NOTICE | E_WARNING));
>    if ($_POST['submit']) {
>      # "a" for append
>      $file = fopen($guestbook, "a");
>      if (!$file) {
>        echo "Can't write to guestbook file";
>        die;
>      }
>      # Grab the form fields
>      $title = $_POST['title'];
>      $data = $_POST['data'];
>      # Remove dangerous characters, and limit the length
>      $title = clean($title, 40);
> $data=nl2br($data);
>
>      fwrite($file,
>        "$data\n");
>      fclose($file);
>    }
>
>    function clean($title, $max) {
>      # Turn tabs and CRs into spaces so they can't
>      # fake other fields or extra entries
>      $title = ereg_replace("[[:space:]]", ' ', $title);
>      # Escape < > and and & so they
>      # can't mess withour HTML markup
>      $title = ereg_replace('&', '&amp;', $title);
>      $title = ereg_replace('<', '&lt;', $title);
>      $title = ereg_replace('>', '&gt;', $title);
>      # Don't allow excessively long entries
>      $title = substr($title, 0, $max);
>      return $title;
>    }
> ?>
> <form action="<?php $_SERVER['php self']  ?>" method="POST">
> <input name="title" maxlength="40">
> <br /><br />
> <textarea name="data" cols="30" rows="30" maxlength="6000"></textarea>
> <br /><br />
> <input type="submit" name="submit" value="Submit">
> --
>
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>



More information about the thelist mailing list