|
Posted by SuperKoko on November 21, 2007, 8:47 am
Please log in for more thread options
On Tue, 20 Nov 2007 11:24:39 +0100, Icarus - iD_Ten_T helper
> I want to parse the text from a <textarea> form element but when I
> pass this in a POST request to the server and then output it using
> PHP, all formatting is gone.
>
> I was under the impresssion that the textbox would register any
> carriage returns or line breaks and send them in the final text for
> processing?
Yes, it does. HTTP POST requests for textareas with existing user
agents, are done in plain text with carriage returns preserved.
Most probably you simply passed this data to the HTML output of your
PHP script without modifying it. Consequently, the CRLF appears in the
HTML source but HTML, in most places, isn't sensitive to multiple
whitespaces.
If you need to output pre-formatted data (which is exactly what you
request), then, use the PRE HTML element.
<pre>
**************************
** Pre-formatted text **
** can be put here **
**************************
</pre>
> Is there any way of forcing the textarea input to send formatting data
> as well?
>
It does.
> Essentially the idea would be to turn a text box with this in:
> "Hello <= carriage return
> <= line break
> World <= carriage return
> <= line break
> Foo <= carriage return
> <= line break
> Bar"
>
> into
> "<p>Hello</p>
> <br />
> <p>World</p>
> <br />
> <p>Foo</p>
> <br />
> <p>Bar</p>"
>
Awful non-sense non-semantic code.
The pre-formatted text I've shown above doesn't consist of paragraphs.
Moroever, you would have issues with multiple spaces.
|