Welcome Guest, Not a member yet? Register   Sign In
Storing and displaying pre-formatted text
#1

[eluser]ajknodel[/eluser]
I have a part of my website where I want to have users input some text that can be formatted. When I say formatted I don't mean bold or italic or anything like that. I just mean that when they hit return, I want that return to be saved and displayed in that way. I have a feeling that this is more of a display problem than a storage problem because when I add <pre> tags to the HTML it works (sort of, but it horribly breaks tables - it at least shows that it was stored right).

Is the only way to display this by storing HTML along side the text I want displayed? Is there an easier way? All I'm doing is assigned the query field to a variable and then echo'ing the variable. Is there something else I should be doing?

If I do have to store HTML to format the text, is there a down side to using something like CK Editor? Is it a security risk?
#2

[eluser]WebsiteDuck[/eluser]
If the returns are stored correctly in the database, you might try using this php function:

Code:
echo nl2br("foo isn't\n bar");
#3

[eluser]ajknodel[/eluser]
[quote author="WebsiteDuck" date="1263117655"]If the returns are stored correctly in the database, you might try using this php function:

Code:
echo nl2br("foo isn't\n bar");
[/quote]That works wonderfull! Thanks!
#4

[eluser]Colin Williams[/eluser]
P tags would be better. CodeIgniter has a Typography class to do this. Check it out in the user guide
#5

[eluser]WebsiteDuck[/eluser]
Ah very cool, never looked into the typography class




Theme © iAndrew 2016 - Forum software by © MyBB