Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    70
    Thanks
    5
    Thanked 0 Times in 0 Posts

    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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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.

  • #4
    New Coder
    Join Date
    Jul 2012
    Posts
    70
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,281
    Thanks
    57
    Thanked 523 Times in 510 Posts
    Blog Entries
    5
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •