Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-09-2012, 10:33 PM   PM User | #1
Spudster
New Coder

 
Join Date: Jul 2012
Posts: 58
Thanks: 5
Thanked 0 Times in 0 Posts
Spudster is an unknown quantity at this point
Spacing With PHP!!

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,

Spudster
Spudster is offline   Reply With Quote
Old 10-09-2012, 11:22 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 10-10-2012, 02:38 AM   PM User | #3
outspoken
New to the CF scene

 
Join Date: Oct 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
outspoken is an unknown quantity at this point
pre

I tend to use <pre></pre> to wrap my text that needs to keep the format created from a textarea within a form.

Code:
<body>
<pre>
this is the 
easy way to format 
simple form text.
</pre>
</body>
it could also look like

Code:
<body>
<pre><?PHP echo $StuffFromTextArea; ?></pre>
</body>
goodluck.
outspoken is offline   Reply With Quote
Old 10-11-2012, 12:45 PM   PM User | #4
Spudster
New Coder

 
Join Date: Jul 2012
Posts: 58
Thanks: 5
Thanked 0 Times in 0 Posts
Spudster is an unknown quantity at this point
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.
Spudster is offline   Reply With Quote
Old 10-11-2012, 01:54 PM   PM User | #5
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,667
Thanks: 46
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:09 AM.


Advertisement
Log in to turn off these ads.