Welcome Guest, Not a member yet? Register   Sign In
Output a text from database. Best practice
#1

[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 *.." ?
#2

[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
#3

[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;
#4

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

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

[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!!




Theme © iAndrew 2016 - Forum software by © MyBB