Page 1 of 2 12 LastLast
Results 1 to 8 of 12

Thread: Line breaks in PHP

  1. #1
    Junior Member trobbins22's Avatar
    Join Date
    Jan 2007
    Traverse City Mi

    Line breaks in PHP

    Does anyone know how to put line-breaks in PHP content?
    have a Flash contact form that send data to a PHP post script. That then send s the info to an e-mail account, but when it gets there the info doesn't have any breaks.

    Is there a way to put breaks in the content that the e-mail shows? Please help.
    Also, if you could show me an example it would help because Im not to familiar with PHP syntax. Sorry for asking for so much. Please help!

    Thanks much
    I do websites at

  2. #2
    Experienced Member < Forum Moderator > Russlock's Avatar
    Join Date
    Jan 2007
    Middlesbrough, Teesside
    I think it's something like this to force a line feed.

    It's not what you know or who you know, it's what you know about who you know !!!

    Website design you CAN afford

  3. #3

  4. #4
    If you are using double quotes (") around your body content, you can use \n for a line break. However, if you are using single quotes (') around your body, you can simply enter a line.

    Example (")
    $body = "Line One\nLine Two";
    This would come out as:
    Line One
    Line Two

    Example (')
    $body = 'Line One
    Line Two';
    This would also come out as:
    Line One
    Line Two

  5. #5

    Line break in PHP

    To create a line break in PHP, all you have to do is put the code


    in the echo statement.

    Check out this tutorial:
    How to Create a Line Break in PHP

  6. #6
    sarcastic encouragement, brilliant! rossable's Avatar
    Join Date
    Oct 2007
    Columbus, Ohio, United States

    My Social Networking

    Follow rossable On Twitter Add rossable on Facebook Add rossable on Google+
    Add rossable on Linkedin Visit rossable's Youtube Channel
    Quote Originally Posted by dlhylton View Post
    To create a line break in PHP, all you have to do is put the code


    in the echo statement.

    Check out this tutorial:
    How to Create a Line Break in PHP

    depending on the DTD it may need a space/ before the close.

    the real question is if the line break is content or styling... style should always be done with CSS. content should technically be done with p tags.

    web standards, look 'em up!
    website | not a website - great design forces grokking.

  7. #7
    Freelance Web Designer - Leeds wayneambler's Avatar
    Join Date
    Jul 2011
    Leeds, West Yorkshire
    Yes, as said previously the code for a line break is simply \n - an example of this for use in a contact form would be:

    $msg = "Name: ".$_POST["name"]."\n";
    $msg .= "E-Mail: ".$_POST["email"]."\n";
    $msg .= "Comment: ".$_POST["comment"]."\n";
    Wayne Ambler - Freelance Web Designer // Writer // Photographer
    Visit my Website, Follow me on Twitter, Send me an E-Mail

  8. #8
    Use the nl2br() function which inserts HTML line breaks (<br />) in front of each newline (\n) in a string. Try this function to break a sentences.

    echo nl2br("One line.\nAnother line.");
    One line.
    Another line.
    For more information, look at this:
    Last edited by James_Smith; 15-10-2012 at 10:32 AM.

Page 1 of 2 12 LastLast

Similar Threads

  1. anna-om-line
    By Toon in forum Illustration Graphic Design
    Replies: 3
    Last Post: 25-02-2009, 12:59 PM
  2. On-Line Invoicing
    By Picha in forum Graphic Design Business Forum
    Replies: 2
    Last Post: 14-02-2008, 12:01 PM
  3. Which Tag Line??
    By Toon in forum Graphic Design and Web Design Help
    Replies: 17
    Last Post: 02-10-2007, 01:06 PM

Posting Permissions

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