retaining and displaying line returns in a text field

retaining and displaying line returns in a text field

am 06.01.2006 12:34:52 von swoll2

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
remarks....as 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

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: retaining and displaying line returns in a text field

am 06.01.2006 23:55:18 von Jordan Miller

The function you need is called nl2br:

http://us2.php.net/nl2br

-Jordan


On Jan 6, 2006, at 5:34 AM, swoll2 wrote:

> 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
> remarks....as 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
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: retaining and displaying line returns in a text field

am 07.01.2006 01:04:42 von Frank Flynn

--Apple-Mail-5--628706759
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed

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

 tags:

echo "
 $rmks
";

Or replace the \n with "
"

$newRmks = str_replace ( "\n", "
", $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,
Frank

On Jan 6, 2006, at 2:45 PM, php-db-digest-help@lists.php.net wrote:

> From: "swoll2"
> Date: January 6, 2006 3:34:52 AM PST
> To: php-db@lists.php.net
> 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
> remarks....as 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
>
>


--Apple-Mail-5--628706759--

Re: retaining and displaying line returns in a text field

am 08.01.2006 15:32:27 von El Bekko

Frank Flynn wrote:
> 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

 tags:
>
> echo "
 $rmks
";
>
> Or replace the \n with "
"
>
> $newRmks = str_replace ( "\n", "
", $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,
> Frank
>
> On Jan 6, 2006, at 2:45 PM, php-db-digest-help@lists.php.net wrote:
>
>> From: "swoll2"
>> Date: January 6, 2006 3:34:52 AM PST
>> To: php-db@lists.php.net
>> 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
>> remarks....as 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
>>
>>
>
>

When echoing, use this:

echo nl2br($rmks);

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php