0

I am trying to find a good way to parse the input from a textarea into HTML (including line breaks etc) Basically the user needs to be able to not enter markup in order to keep the format they enter their data in.

For instance if they enter:

Here is some text
Here is some more text

I need it to come out like that...not like

Here is some textHere is some more text

I know sites like LiveJournal and other blogging sites are able to do this, i just have no idea where to look. It almost seems like something that needs to be done pre-submit in the browser since form submission seems to lose the formatting.

Thanks for any help!

-Dan

3
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by silverdollar
0

Feed it through nl2br.

If you look at the source code, you'll see that's formatted while the text is not.

(Note: I'm having trouble accessing php.net at the moment, so the function name may be wrong. If it is, it will at least steer you in the right direction.)

0

Also don't forget to use htmlspecialchars. To convert these symbols:

> " ' &
<?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; // &lt;a href='test'&gt;Test&lt;/a&gt;
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.