Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 diskhub

diskhub
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 09 December 2005 - 03:27 PM

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?



#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 09 December 2005 - 03:38 PM

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

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 diskhub

diskhub
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 09 December 2005 - 04:59 PM

[!--quoteo(post=325927:date=Dec 9 2005, 11:38 PM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Dec 9 2005, 11:38 PM) View Post[/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']);
[/quote]

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.


#4 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 09 December 2005 - 05:53 PM

no, you don't need to store <br>. just use nl2br on the column retrieved from the db.
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#5 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 09 December 2005 - 06:51 PM

[!--quoteo(post=325977:date=Dec 9 2005, 12:53 PM:name=ryanlwh)--][div class=\'quotetop\']QUOTE(ryanlwh @ Dec 9 2005, 12:53 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
no, you don't need to store <br>. just use nl2br on the column retrieved from the db.
[/quote]

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
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#6 diskhub

diskhub
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 10 December 2005 - 01:44 AM

[!--quoteo(post=325989:date=Dec 10 2005, 02:51 AM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Dec 10 2005, 02:51 AM) View Post[/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
[/quote]


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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users