CodeIgniter Forums
Storing and displaying pre-formatted text - 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: Storing and displaying pre-formatted text (/showthread.php?tid=26262)



Storing and displaying pre-formatted text - El Forum - 01-09-2010

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


Storing and displaying pre-formatted text - El Forum - 01-09-2010

[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");



Storing and displaying pre-formatted text - El Forum - 01-09-2010

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


Storing and displaying pre-formatted text - El Forum - 01-09-2010

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


Storing and displaying pre-formatted text - El Forum - 01-10-2010

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