<br /> in html 4

Discussion in 'HTML' started by Barbara de Zoete, Jul 18, 2005.

  1. On Mon, 18 Jul 2005 22:20:08 +0100, Robert Frost-Bridges
    <> wrote:

    > Following a suggestion in another thread to investigate the php function
    > nl2br() I have been able to format content inputted via a textarea into
    > separate paragraphs (well line breaks anyway). These line breaks however
    > are the xhtml <br /> (which they are supposed to be) but the page is html
    > 4.01. If I validate it however it checks out fine but I'm not sure why? Is
    > <br /> ok to use then?


    How about checking it yourself
    <http://www.w3.org/TR/html401/index/elements.html> ?

    --
    ,-- --<--@ -- PretLetters: 'woest wyf', met vele interesses: ----------.
    | weblog | http://home.wanadoo.nl/b.de.zoete/_private/weblog.html |
    | webontwerp | http://home.wanadoo.nl/b.de.zoete/html/webontwerp.html |
    |zweefvliegen | http://home.wanadoo.nl/b.de.zoete/html/vliegen.html |
    `-------------------------------------------------- --<--@ ------------'
     
    Barbara de Zoete, Jul 18, 2005
    #1
    1. Advertising

  2. Following a suggestion in another thread to investigate the php function
    nl2br() I have been able to format content inputted via a textarea into
    separate paragraphs (well line breaks anyway). These line breaks however
    are the xhtml <br /> (which they are supposed to be) but the page is html
    4.01. If I validate it however it checks out fine but I'm not sure why? Is
    <br /> ok to use then?
    (It's the page in my sig if you need to see it).

    regards,
    --
    Robert
    http://brightonfixedodds.net
     
    Robert Frost-Bridges, Jul 18, 2005
    #2
    1. Advertising

  3. On Mon, 18 Jul 2005 22:30:48 +0100, Robert Frost-Bridges
    <> wrote:

    > Barbara de Zoete wrote:
    >
    >> How about checking it yourself
    >> <http://www.w3.org/TR/html401/index/elements.html> ?

    >
    > I did. It says end tag forbidden but doesn't seem to mention <br />.
    >


    It gives <br> as the proper syntax for the element. So if <br /> validates in an
    otherwise html4 document, something else is going on.

    --
    ,-- --<--@ -- PretLetters: 'woest wyf', met vele interesses: ----------.
    | weblog | http://home.wanadoo.nl/b.de.zoete/_private/weblog.html |
    | webontwerp | http://home.wanadoo.nl/b.de.zoete/html/webontwerp.html |
    |zweefvliegen | http://home.wanadoo.nl/b.de.zoete/html/vliegen.html |
    `-------------------------------------------------- --<--@ ------------'
     
    Barbara de Zoete, Jul 18, 2005
    #3
  4. Barbara de Zoete wrote:

    > How about checking it yourself
    > <http://www.w3.org/TR/html401/index/elements.html> ?


    I did. It says end tag forbidden but doesn't seem to mention <br />.

    --
    Robert
    http://brightonfixedodds.net
     
    Robert Frost-Bridges, Jul 18, 2005
    #4
  5. Robert Frost-Bridges wrote:

    > Following a suggestion in another thread to investigate the php function
    > nl2br() I have been able to format content inputted via a textarea into
    > separate paragraphs (well line breaks anyway). These line breaks however
    > are the xhtml <br /> (which they are supposed to be) but the page is html
    > 4.01. If I validate it however it checks out fine but I'm not sure why? Is
    > <br /> ok to use then?


    Short version: No

    Longer version: It means the same as <br>&gt; - and some browsers do render
    it as such.

    Long version: http://www.cs.tut.fi/~jkorpela/html/empty.html

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Jul 18, 2005
    #5
  6. Barbara de Zoete wrote:

    > It gives <br> as the proper syntax for the element. So if <br /> validates
    > in an otherwise html4 document, something else is going on.


    That's what I'm wondering.

    regards,
    --
    Robert
    http://brightonfixedodds.net
     
    Robert Frost-Bridges, Jul 18, 2005
    #6
  7. In news:,
    Robert Frost-Bridges <> wrote:
    > Following a suggestion in another thread to investigate the php
    > function nl2br() I have been able to format content inputted via a
    > textarea into separate paragraphs (well line breaks anyway). These
    > line breaks however are the xhtml <br /> (which they are supposed to
    > be) but the page is html
    > 4.01. If I validate it however it checks out fine but I'm not sure
    > why? Is <br /> ok to use then?
    > (It's the page in my sig if you need to see it).
    >
    > regards,


    I wrote this a while back when I was learning php, so it's a little
    over-verbose:

    function text_to_paragraphs($text) {
    // Return formatted string only if not empty
    if (!eregi('^\s*$',$text)) {
    // Strip final whitespace
    $text = trim($text);
    // Add <p> to start of string
    $text = ereg_replace("^", "<p>", $text);
    // Add </p> to end of string
    $text = ereg_replace("$", "</p>", $text);
    // Stick </p><p> at line ends
    $text = ereg_replace("(\r\n|\n|\r)", "</p><p>", $text);
    // Chop last <p>
    $text = ereg_replace("<p>$", "", $text);
    return ($text);
    } else {
    return false;
    }
    }

    --
    Andrew @ Rockface
    np: (Winamp is not active ;-)
    www.rockface-records.co.uk
     
    Andrew @ Rockface, Jul 19, 2005
    #7
  8. Robert Frost-Bridges, Jul 19, 2005
    #8
  9. Robert Frost-Bridges wrote:

    >> Long version: http://www.cs.tut.fi/~jkorpela/html/empty.html

    >
    > Thanks David, I might have known Jukka would have a take on this. Reading
    > it however, it still seems to imply that <br /> should not validate to
    > html 4 strict. And yet http://brightonfixedodds.net/br_test.html does.


    So does: "<p> <br>> </p>"
    But "<meta>> </head>" won't

    Character data is allowed in divs.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Jul 19, 2005
    #9
  10. Andrew @ Rockface wrote:

    > I wrote this a while back when I was learning php, so it's a little
    > over-verbose:

    [..code..]

    What can I say Andrew, this is just what I'm looking for and works
    perfectly. Now to dissect it. (nicely commented too btw, again thank you).

    --
    Robert
    http://brightonfixedodds.net
     
    Robert Frost-Bridges, Jul 19, 2005
    #10
  11. David Dorward wrote:

    > Robert Frost-Bridges wrote:
    >
    >>> Long version: http://www.cs.tut.fi/~jkorpela/html/empty.html

    >>
    >> Thanks David, I might have known Jukka would have a take on this. Reading
    >> it however, it still seems to imply that <br /> should not validate to
    >> html 4 strict. And yet http://brightonfixedodds.net/br_test.html does.

    >
    > So does: "<p> <br>> </p>"
    > But "<meta>> </head>" won't
    >
    > Character data is allowed in divs.


    Ah yes, I've got it now. Thank you for your time.

    --
    Robert
    http://brightonfixedodds.net
     
    Robert Frost-Bridges, Jul 19, 2005
    #11
  12. Barbara de Zoete

    Andy Dingley Guest

    On Tue, 19 Jul 2005 22:18:57 +0100, Robert Frost-Bridges
    <> wrote:

    >Reading it
    >however, it still seems to imply that <br /> should not validate to html 4
    >strict.


    No, it's valid. It's just that it means

    "linebreak
    >"


    rather than merely "linebreak"


    It's still not a good idea to do it.
     
    Andy Dingley, Jul 19, 2005
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Kamoski
    Replies:
    1
    Views:
    7,180
  2. Mitchua
    Replies:
    1
    Views:
    7,155
    Ice Demon
    Jul 15, 2003
  3. Laura
    Replies:
    1
    Views:
    567
    Gunnar Hjalmarsson
    Jun 5, 2004
  4. Matthew Louden
    Replies:
    1
    Views:
    7,105
    Scott M.
    Oct 11, 2003
  5. Adam Akhtar
    Replies:
    9
    Views:
    594
    Florian Gilcher
    Aug 16, 2008
Loading...

Share This Page