views:

189

answers:

1

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.

EDIT: Wow, was expecting more responses to this. Either most people use wysiwyg editors and/or direct output to browser and/or use basic functions like nl2br. I'll give this question another day.

A: 

If you check it out you'll see it does some heavy lifting with about 20 regular expressions.

I think you shouldn't be afraid of 20 regular expressions. They aren't demons of speed, but they aren't so slow in fact. Most of sites converts content from some kind of BBCode/Textile/Markdown/others format to HTML just before displaying... and often they do this 20 times for a single page.

Crozin
I know, if WordPress is using this function then I shouldn't lose to much sleep over this. But the function is geared for WordPress and I just want to ask what techniques others have used.
zaf
Why not use Cache I would use http://wordpress.org/extend/plugins/wp-super-cache/ :) so you only go thru it one time.
JeremySpouken
I'm just using one function from the wordpress codebase. But I can and do use caching. The question is about what function others use for formatting the text.
zaf