diskhub Posted December 9, 2005 Share Posted December 9, 2005 Hi, I have been doing a lot of form using php to pass the inputs into mysql database. However, most of the time i have been doing a <br> insertion if i want a break or two in the entry to create a nicer appearance for my text when i were to query it out from mysql. Is this method the right way? Cos i have been thinking that this method really sux alot especially for users who don't know html and when they input something into the textarea, i couldn't expect them to type "<br><br>" into their text. Can anyone tell me how to do this without having to educate users to type in the "<br>" and store them uglily into the database? Quote Link to comment Share on other sites More sharing options...
obsidian Posted December 9, 2005 Share Posted December 9, 2005 let's say you've just submitted the form, and the $_POST['text'] variable holds your textarea input... just use the nl2br() function, and it will change all the newlines to <br /> tags for you: echo nl2br($_POST['text']); Quote Link to comment Share on other sites More sharing options...
diskhub Posted December 9, 2005 Author Share Posted December 9, 2005 [!--quoteo(post=325927:date=Dec 9 2005, 11:38 PM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Dec 9 2005, 11:38 PM) 325927[/snapback][/div][div class=\'quotemain\'][!--quotec--] let's say you've just submitted the form, and the $_POST['text'] variable holds your textarea input... just use the nl2br() function, and it will change all the newlines to <br /> tags for you: echo nl2br($_POST['text']); Hi, so does it mean that my database still has to store the <br> in it? Can i keep my database free from "<br>" but yet display it when i draw out the data? Please advise. Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted December 9, 2005 Share Posted December 9, 2005 no, you don't need to store <br>. just use nl2br on the column retrieved from the db. Quote Link to comment Share on other sites More sharing options...
obsidian Posted December 9, 2005 Share Posted December 9, 2005 [!--quoteo(post=325977:date=Dec 9 2005, 12:53 PM:name=ryanlwh)--][div class=\'quotetop\']QUOTE(ryanlwh @ Dec 9 2005, 12:53 PM) 325977[/snapback][/div][div class=\'quotemain\'][!--quotec--] no, you don't need to store <br>. just use nl2br on the column retrieved from the db. exactly. it's much more advisable to use nl2br() when you're displaying the info as opposed to when you insert it to your DB Quote Link to comment Share on other sites More sharing options...
diskhub Posted December 10, 2005 Author Share Posted December 10, 2005 [!--quoteo(post=325989:date=Dec 10 2005, 02:51 AM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Dec 10 2005, 02:51 AM) 325989[/snapback][/div][div class=\'quotemain\'][!--quotec--] exactly. it's much more advisable to use nl2br() when you're displaying the info as opposed to when you insert it to your DB Hey, ok thanks for your help. Just one more question, do i have to store css class as i would like th change the font colour of the words too... And how do this reply page have this good box for replying, how do they implement? They use java? Cos i would like users to highlight certain part of the words and choose the style they want? how do i do that? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.