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

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.)

Member Avatar for iamthwee

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;
?>

Thanks a ton! This is exactly what i was looking for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.