ironside82 Posted March 30, 2007 Share Posted March 30, 2007 I have a forum on my site for people to post messages. Is there a way to get the text to format correctly when the user posts it? At the moment if a user types the following: ---- Hello everyone here is my shopping list: -egg -cheese -milk -bread ---- The results will look like: "Hello everyone here is my shopping list: -egg -cheese -milk -bread" All on the same line! How do I get it to recognize that there has been a new line created or any other html formatting for example and transfer it to the database so its displays correctly when it is recalled? Thanks for your help James Link to comment https://forums.phpfreaks.com/topic/44984-text-formatting-question/ Share on other sites More sharing options...
Caesar Posted March 30, 2007 Share Posted March 30, 2007 That depends on a couple of things. How are you storing the input? Are ypur processing or cleaning the text in a function prior to throwing it into your db? One quick solution is to do: <?php $newtext = str_replace("\n","<br>",$posted_text); ?> Link to comment https://forums.phpfreaks.com/topic/44984-text-formatting-question/#findComment-218386 Share on other sites More sharing options...
AndyB Posted March 30, 2007 Share Posted March 30, 2007 nl2br() on the output from the database Link to comment https://forums.phpfreaks.com/topic/44984-text-formatting-question/#findComment-218410 Share on other sites More sharing options...
neel_basu Posted March 31, 2007 Share Posted March 31, 2007 Dont Forget To Use addslashes() and stripslashes() Link to comment https://forums.phpfreaks.com/topic/44984-text-formatting-question/#findComment-218543 Share on other sites More sharing options...
ironside82 Posted March 31, 2007 Author Share Posted March 31, 2007 That worked a treat, thanks guys. I'm guessing getting bold underline and italic tags in are a little trickier! Link to comment https://forums.phpfreaks.com/topic/44984-text-formatting-question/#findComment-218561 Share on other sites More sharing options...
ted_chou12 Posted March 31, 2007 Share Posted March 31, 2007 the most important function you should include is htmlentities() this formats the characters to non special characters that dont get recognized by html, so your page is not effected with user's spamming html codes. Ted Link to comment https://forums.phpfreaks.com/topic/44984-text-formatting-question/#findComment-218568 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.