This is an HTML issue (not PHP or MySQL) that is HTML ignores carriage returns (and most other white spaces).

There are two simple solutions:

use <pre> tags:

  echo " <pre> $rmks</pre>";

Or replace the \n with "<br>"

  $newRmks = str_replace ( "\n", "<br>", $rmks );
  echo $newRmks;

You can do this going into or coming out of the database but remember to be consistent. And you can do more with paragraphs and changing tabs and other special characters - there are probably some libraries that will all this and much more (including some WISIWYG editors that you can put on your web page) depending on how deep you want to get.

Good Luck,

On Jan 6, 2006, at 2:45 PM, [EMAIL PROTECTED] wrote:

From: "swoll2" <[EMAIL PROTECTED]>
Date: January 6, 2006 3:34:52 AM PST
Subject: retaining and displaying line returns in a text field

Good morning -

I'm trying to get a text field with line returns in it to be stored,
retrieved, and displayed the way it gets entered.

Specifically, my users use a form field (html textarea) to enter some they enter their remarks, they can hit Enter to insert a hard
return, which is reflected in the textarea on their screen.

Example entry:
this is line1.
this is line2.
this is line3.

Those remarks get uploaded into a mysql db, into a field defined as a text
field named rmks.

If I use PhpMyAdmin to browse the table, it shows the entry with the lines
separated, but there are no /n's or other control characters visible.

Later, the field is retrieved from the db using a php script and assigned to a variable $rmks....when I echo $rmks, it displays on a single line without
the line returns, like this:

this is line1.this is line2.this is line3.

I have tried to work with addslashes and stripslashes, but neither has
worked.  I think I'm just missing something basic....

Appreciate any help or points to previous discussions......thanks...Steve

Reply via email to