CodeIgniter Forums
Output a text from database. Best practice - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Output a text from database. Best practice (/showthread.php?tid=43465)



Output a text from database. Best practice - El Forum - 07-12-2011

[eluser]dimaomni[/eluser]
Hi guys!

I have a question how to output from DB type TEXT?
Or more exactly I output this data and they are outputted in one row at my webpage.
And there is no any carry (carriage return)in a text which is stored in DB.

Quote:So what is the best practice?

Should I take care about CR before putting data to DB or count chars and divide text by <br /> after "SELECT *.." ?


Output a text from database. Best practice - El Forum - 07-12-2011

[eluser]tehknox[/eluser]
Hi dimaomni,

How is your data collected from the user (textbox, textarea, CKEditor)? When you want to insert data and keep all special characters, you should use a web text editor like CKEditor or TinyMCE because textarea and textbox doesn't keep/care about special character. The CR is not written in the text it's only a fake view.

Maybe I'm wrong, but I've never been able to get CR in a textarea without writing HTML code directly in it (<br />).

Best Regards,
tehknox


Output a text from database. Best practice - El Forum - 07-12-2011

[eluser]John_Betong_002[/eluser]
I always store my raw text to a table field and use this to output the result:

Code:
&lt;?php echo nl2br( $text ); ?&gt;
&nbsp;
&nbsp;


Output a text from database. Best practice - El Forum - 07-12-2011

[eluser]dimaomni[/eluser]
Thank you a lot!


Output a text from database. Best practice - El Forum - 07-12-2011

[eluser]tehknox[/eluser]
Yeah! nl2br() is a good way of doing it!


Output a text from database. Best practice - El Forum - 07-13-2011

[eluser]lefoup[/eluser]
[quote author="John_Betong_002" date="1310505662"]I always store my raw text to a table field and use this to output the result:

Code:
&lt;?php echo nl2br( $text ); ?&gt;
&nbsp;
&nbsp;[/quote]

Nice idea, thanks for the post, I'll give that a go!!