to wordwrap, nl2br or format on the db end

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

to wordwrap, nl2br or format on the db end

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

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