How to format text from HTML textarea?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • deko

    How to format text from HTML textarea?

    I have a feedback form on my website with a textarea for visitors to type
    comments, etc. Nothing special. When users click the "Send" button, the form
    posts, and I copy the contents of the textarea to a file like this:

    $feedback = trim($_POST['feedback_texta rea']);
    $fp = fopen($feedback _file,'a');
    fwrite($fp, $feedback);
    fclose($fp);

    The problem is the line breaks in the textarea are lost when copied to the file.

    For example:

    This is a line.

    This is a new line.

    This is another new line.

    becomes:

    This is a line. This is a new line. This is another new line.

    And this:

    This is a "test"

    becomes:

    This is a \"test\"

    Is there a way to preserve line breaks and other formatting when coping to a
    file from a HTML textarea?


  • Jensen Somers

    #2
    Re: How to format text from HTML textarea?

    On Sat, 17 Mar 2007 05:56:39 -0700, deko wrote:
    I have a feedback form on my website with a textarea for visitors to type
    comments, etc. Nothing special. When users click the "Send" button, the form
    posts, and I copy the contents of the textarea to a file like this:
    >
    $feedback = trim($_POST['feedback_texta rea']);
    $fp = fopen($feedback _file,'a');
    fwrite($fp, $feedback);
    fclose($fp);
    >
    The problem is the line breaks in the textarea are lost when copied to the file.
    >
    For example:
    >
    This is a line.
    >
    This is a new line.
    >
    This is another new line.
    >
    becomes:
    >
    This is a line. This is a new line. This is another new line.
    >
    And this:
    >
    This is a "test"
    >
    becomes:
    >
    This is a \"test\"
    >
    Is there a way to preserve line breaks and other formatting when coping to a
    file from a HTML textarea?
    Use the nl2br() function when printing out that
    information. (http://www.php.net/nl2br )

    To remove the \ signs there is a function called strip_slashes() .

    Regards,
    Jensen

    Comment

    • deko

      #3
      Re: How to format text from HTML textarea?

      >Is there a way to preserve line breaks and other formatting when coping to a
      >file from a HTML textarea?
      >
      Use the nl2br() function when printing out that
      information. (http://www.php.net/nl2br )
      >
      To remove the \ signs there is a function called strip_slashes() .
      Thanks for the tip. This seems to do the trick:

      $feedback = trim($_POST['feedback_texta rea']);
      $feedback = nl2br($feedback );
      $feedback = stripslashes($f eedback);

      That was easy :)

      Comment

      Working...