Re: Keeping newlines when sending form
| From: | Monte Ohrt | Date: | Tue, 12 Sep 2000 20:09:21 +0000 |
| Subject: | Re: Keeping newlines when sending form | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-16435@lists.php.net to get a copy of this message | ||
Hi Carlo,
When your textfield is submitted to the php script, the carriage returns
are kept in tact. However, HTML does not respect carriage returns by
default, it will display them as a single space.
If your goal is to display your text in HTML respecting carriage
returns, you can convert all \n to <BR>, which is quite easy with the
nl2br() function in php.
Another possible solution is preformatting the HTML text like so:
<PRE>
<?php echo $text; ?>
</PRE>
which has the side effect of displaying fixed width fonts, which may or
may not be what you want.
For most applications, it is best to keep the text in its original form
in the database, and converting your carriage returns just before
displaying via HTML. This way if you ever need to use your data for
other purposes besides HTML, you won't have those <br> tags in the
original text.
Monte
Carlo van Herwaarden wrote:
>
> Hello,
>
> I'm trying to send a form textfield to my php script with something in it
> like this.
>
> bla bla and bla (notice the empty lines)
> bla
>
> bla bla bla
>
> If i echo the form data all the newlines are gone and it will look like this
>
> bla bla and bla (notice the empty lines) bla bla bla bla
>
> Is there a way to keep the returns or find them and then replace them with
> <br> when echoing or storing in my mysql dBase? I want to use it to store
> pages of text with all the returns intact.
>
> Carlo
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
Monte Ohrt <monte@ispi.net>
http://www.ispi.net/