View Full Version : Spacing With PHP!!

10-09-2012, 11:33 PM
Hey, just need to ask a quick question...

How do i make a line break in PHP

so if user does this

//goes to a new line, it will take them to the new line instead of submiting the form on the name line..

i have heard the nblr2 function but thats adding <br> in text fields, like on this and the examples i have shown above

Thanks Hoping to get an answer,


10-10-2012, 12:22 AM
For input, the only way to go to a new line is to use a <textarea> element which supports new lines. You can store this data raw as it will contain the linefeeds within it, but to display it in HTML you need to use nl2br to add <br/> to it.
If the input they are on is not a textarea, hitting the enter key will submit the form. You can't do anything to control that in PHP, that would require that JS be in use to respond to the event instead.

10-10-2012, 03:38 AM
I tend to use <pre></pre> to wrap my text that needs to keep the format created from a textarea within a form.

this is the
easy way to format
simple form text.

it could also look like

<pre><?PHP echo $StuffFromTextArea; ?></pre>


10-11-2012, 01:45 PM
Thanks and is there a way to hide <.br> from the users? like on Vbulletin for example where it

goto a new line(like this) but won,t display </br> in the text field.

10-11-2012, 02:54 PM
In a text field it should show up the way it was entered with \n being invisible.

In html use nl2br().

If storing the text in the DB store it there in the way your user entered it and just use nl2br() for html - assume that any time you pull it out will be for a text area.

Thats pretty much the same thing Fou said but with a slightly different twist on the explanation.