nl2br in textarea

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

jarow
Forum Commoner
Posts: 83
Joined: Tue Jan 28, 2003 2:58 am

nl2br in textarea

Post by jarow »

When this runs in the body of my page it works perfectly, seperating the lines fine without printing the actual code <br> and </br>:

<?php echo nl2br ($row_cv['proyecto']); ?>

however when I place this within a text area

<textarea name="textarea"><?php echo nl2br ($row_cv['publicaciones']); ?></textarea>

the text in the text box prints out each <br> and </br>

what gives?
Goowe
Forum Commoner
Posts: 94
Joined: Mon Mar 15, 2004 9:51 am
Location: Southeast Alaska

Post by Goowe »

Just a guess...

I don't think textboxes will let HTML be run through them... I think if you don't worry about running the nl2br function on it, it will still return in the textbox?

Good luck :roll:
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

nlbr is a function, assign it a variable.

ie:

Code: Select all

$char = nl2br($text);

<textarea>$char</textarea>
also I think goowe has a point, the html will parse the line breaks itself
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

also try
<textarea value=$text></textarea>

not sure what your doing 100%
darkforcesjedi
Forum Newbie
Posts: 5
Joined: Sat Mar 27, 2004 1:33 pm

Post by darkforcesjedi »

I don't think you need the function at all.

<textarea>this
is
a
test</textarea>

puts all that on different lines. so

<textarea><?PHP echo "this\nis\na\ntest" ?></textarea>

should do the same
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

^exactly

you'd only need the function if you were outputting to the page, not the textarea (if you know what I mean).

Breaks in text areas are \n, breaks in regular HTML is <br />.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

LiLpunkSkateR wrote:^exactly

you'd only need the function if you were outputting to the page, not the textarea (if you know what I mean).

Breaks in text areas are \n, breaks in regular HTML is <br />.
breaks in Windows are \r\n :wink:
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

vigge89 wrote:breaks in Windows are \r\n :wink:
Breaks in win are CR LF :twisted:
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

breaks in life are...


well,

/

what are breaks in life??? i dont get any
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Snap into a slim jim?
darkforcesjedi
Forum Newbie
Posts: 5
Joined: Sat Mar 27, 2004 1:33 pm

Post by darkforcesjedi »

vigge89 wrote:breaks in Windows are \r\n :wink:
internet explorer is programmed to recognize both types of line breaks. i dunno about mozilla/netscape/opera for windows though. they probably support both as well.
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

LiLpunkSkateR wrote:Snap into a slim jim?
EAT ME!!
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

my mother is the only person I know who could live off beefsticks. she cant leve any type of store that would harbor beefsticks w/o buying 2, one for the walk, 1 for the road.

shes got the bug i guess lol
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

well, breaks in windows could also result in a crash :P
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

</br>??

Don't you mean <br />
Post Reply