www.webdeveloper.com
Results 1 to 7 of 7

Thread: Blank Lines

  1. #1
    Join Date
    Dec 2007
    Location
    Mississippi
    Posts
    1,063

    Blank Lines

    In a HTML form that is processed by PHP:

    Hello

    World!
    Would that be output to the browser as:

    Hello

    World!
    or

    HelloWorld!
    In other words, do you have to do any sort of special formatting in PHP to make it recognize multiple line breaks?

  2. #2
    look at this sample:
    Code:
    $message .= "Hello: " . htmlspecialchars($_POST['hello'], ENT_QUOTES) . "<br>\n";
      $message .= "World: " . htmlspecialchars($_POST['world'], ENT_QUOTES) . "<br>\n";

  3. #3
    Join Date
    Dec 2007
    Location
    Mississippi
    Posts
    1,063
    I'm sorry, but I don't really understand how that accomplishes what I'm trying to do. What I want to do is when someone types:

    This

    and this


    into a HTML form, for the output to be displayed as:

    This

    and this

    rather than

    Thisand this

    I apologize if I didn't make my first post clear enough

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    Either output the text within <pre>...</pre> tags, or run it through the nl2br() function:
    PHP Code:
    echo "<pre>" htmlentities($text) . "</pre>\n";
    // . . . or . . .
    echo "<p>" nl2br(htmlentities($text)) . "</p>\n"
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Dec 2007
    Location
    Mississippi
    Posts
    1,063
    Does either method have an advantage over the other?

  6. #6
    Join Date
    Aug 2007
    Posts
    3,767
    The nl2br is probably best. However, it outputs <br /> so if you are using HTML DOCTYPE, you probably better use
    Code:
    preg_replace("/\n/","<br>",htmlentities($text));
    Great wit and madness are near allied, and fine a line their bounds divide.

  7. #7
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    Ultimately, it comes down to what you are trying to output and how semantically meaningful you want your resulting HTML mark-up to be. You might want to break it up into HTML <p>aragraphs, with:
    PHP Code:
    echo "<p>" preg_replace('/[\r\n]+/'"</p>\n<p>"htmlentities(trim($text))) . "</p>\n"
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles