Jump to content

How they DO THAT in textArea without "<br>"??


Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/3010-how-they-do-that-in-textarea-without/
Share on other sites

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']);

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

 

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.