Textarea to paragraphs
Posted
by zaf
on Stack Overflow
See other posts from Stack Overflow
or by zaf
Published on 2010-03-27T17:36:32Z
Indexed on
2010/03/27
17:43 UTC
Read the original article
Hit count: 410
When I have to render textarea content to the front end I usually pass it thru a function that converts newlines to <br/>
tags and double newlines signal paragraph tags so blocks of text get surrounded by <p>
and </p>
tags.
To save time I usually use a ready made PHP function from the wordpress codebase. You can get the link from the man himself: http://ma.tt/scripts/autop/
If you check it out you'll see it does some heavy lifting with about 20 regular expressions.
I know I could use a wysiwyg editor (like TinyMCE or CKEditor) that can format the data on the client and then send it to the server (most of them add <p>..</p>
tags by default) but I want to know the experience of others in handling raw textarea input and then displaying it on the front end.
© Stack Overflow or respective owner