Page 1 of 1

to wordwrap, nl2br or format on the db end

Posted: Tue Aug 29, 2006 11:23 am
by wtf
Greets,

I've slowly moved to formatting all/most of the formatting work on the db end. So instead of date() I use to_char() which is postgresql function btw, and just echo the output.
For dates and few other things works peachy. However I do have a dillema at the moment.

I need to output some text and I want to output it in same format as it was typed in. I usualy use nl2br or wordwrap to accomplish this, however I'd love to do this on db end and not have to worry about formatting the output by php. Reason for this is because I believe that db will handle this much faster. Only drawback I see to using this method is if I access data from the view for purpose of generating the pdf report or something along those lines where I'd need to strip back the break tags.

I guess, my question pertains to pros and cons of my approach.



"... fool me once ..... uhmmm ..."
~w

Posted: Tue Aug 29, 2006 5:32 pm
by feyd
You'll need to perform such actions during insertion. I wouldn't advise it as you'll have to demuck the data for any other output format including if and when someone wants to edit the text.

Posted: Tue Aug 29, 2006 7:03 pm
by wtf
Data in the table will not be affected. Data in the view would be. Therefore even when I insert/edit the data in the original field I wouldn't have to worry about the formatting. However, something's telling me I'm just looking for trouble ...


Thanks,

~w

Posted: Tue Aug 29, 2006 7:32 pm
by RobertGonzalez
Store the data in as simple a form as possible in the database. Format it for viewing depending on the viewer (browser, PDF, text, spreadsheet). Let the code what it can and leave the data in a simple to use format (similar to wiki style).