Line Breaks for <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

mykg4orce
Forum Newbie
Posts: 21
Joined: Tue May 28, 2002 2:19 pm

Line Breaks for <textarea>

Post by mykg4orce »

Hey!

I have a textarea that is used to submit text for a news posting script, how do I get php to insert line breaks (<br>) automatically when the text wraps in the text box.

Thanks!
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

gr

Post by gotDNS »

Hey, I have the same problem, I think it is something about strict, but I forget....
mykg4orce
Forum Newbie
Posts: 21
Joined: Tue May 28, 2002 2:19 pm

Post by mykg4orce »

i was looking at the phpbb source code and found this:

Code: Select all

&lt;?php
$message = str_replace("\n", "&lt;BR&gt;", $message);
?&gt;
does that have anything to do with it?

:)
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

yeah that would work, but if you want to go all xhtml you'd use <br />
mykg4orce
Forum Newbie
Posts: 21
Joined: Tue May 28, 2002 2:19 pm

Post by mykg4orce »

aaahh, how does that work?
User avatar
fatal
Forum Contributor
Posts: 118
Joined: Sat Apr 20, 2002 10:47 am
Location: East Coast

Post by fatal »

I think you mean the nl2br function: http://www.php.net/manual/en/function.nl2br.php
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

Post by gotDNS »

I don't think so...but i found this:

Code: Select all

<textarea wrap="off">True to the type</textarea>
there is also soft and hard. I thing off will make it so when it is submitted, if you hit enter a bunch of times then type a letter, it will show up the same. I'm testing it now.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

actually, it wouldnt insert a line break when wrapped in the text box, it would insert a break everytime the user hit a line break...

you could tell php to count a certain amount of characters and put a break in though
Last edited by hob_goblin on Tue May 28, 2002 2:32 pm, edited 1 time in total.
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

Post by gotDNS »

ah, my bad...if thats what u meant. I just want the way it is typed to hold true, see, most users don't know html.

P.S. mykg4orce, all tags should be lower case and ones without ending should either be ended or have /. Sorry, if that was just pasted and ur actually neat.
mykg4orce
Forum Newbie
Posts: 21
Joined: Tue May 28, 2002 2:19 pm

Post by mykg4orce »

huh? im sry but is there a functionality to putting a "/" at the end here: <br />

Im sry dont understand, I have done fine, just using <br> in my scripts :)
Last edited by mykg4orce on Tue May 28, 2002 2:35 pm, edited 1 time in total.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

SOFT wraps long lines in the text area for easy editing, much like a word processor. It does not, however, send the carriage returns to the server. This type of wrap is probably the most useful because it is the easiest for the user to edit, but it does not actually change any of their data. HARD looks to the user like SOFT, but the carriage returns the user sees are sent to the server. OFF does not wrap at all; it displays and sends the text exactly as typed in.
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post by lc »

Personally I actually preferr to just not mention the wrap in the textarea itself. This because a lot of the time the textarea may be the same width as is allowed for the message as it gets displayed later, but the font size may well be different. Or they may well differ anyway.
In short I like the width allowed for the entered message to be independant of the textarea width.

I usually work with the wordwrap function but apparently it seems as if a lot of php hosts do not have support for that one. Works nicely though.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

mykg4orce wrote:huh? im sry but is there a functionality to putting a "/" at the end here: <br />

Im sry dont understand, I have done fine, just using <br> in my scripts :)
<br> is HTML and <br /> is XHTML. Basically XHTML is HTML but a bit more strict, all tags have to be closed and be in lowercase and all attributes must be enclosed in double quotes so although

Code: Select all

<IMG SRC="mypic.jpg" WIDTH=12 HEIGHT=45>
is perfectly valid HTML you would need to change it to

Code: Select all

<img src="mypic.jpg" width="12" height="45" />
for it to validate as XHTML transitional. At the moment you can use either HTML or XHTML you don't have to use one or the other. Eventually XHTML will be what most people use though.

Check this thread for more info.

Mac
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post by MattF »

<br> is fine for all versions of HTML, he is talking about XHTML which says that all tags must have an ending eg <img src="" /> and <br /> basically the ones that don't have an ending have a /> insteaad of just an > on the end of the, if you catch my drift....
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

Post by gotDNS »

the / at the end of, usually, unended tags is used in parsing of XML code.
Post Reply