Web Analytics Made Easy -
StatCounter Little problem with nl2br() - CodingForum


No announcement yet.

Little problem with nl2br()

  • Filter
  • Time
  • Show
Clear All
new posts

  • Little problem with nl2br()


    I am using this DOCTYPE:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

    So when I use the code below:

    PHP Code:
    $D_blog nl2br($m_blog); 
    I get <br /> inserted instead of <br>

    This causes me to warnings in my validation:
    Line 95, Column 5: NET-enabling start-tag requires SHORTTAG YES

    <br />

    The sequence <FOO /> can be interpreted in at least two different ways, depending on the DOCTYPE of the document. For HTML 4.01 Strict, the '/' terminates the tag <FOO (with an implied '>'). However, since many browsers don't interpret it this way, even in the presence of an HTML 4.01 Strict DOCTYPE, it is best to avoid it completely in pure HTML documents and reserve its use solely for those written in XHTML.
    Reading the manual it seems that I should
    insert a "false" parameter like this:

    PHP Code:
    But when I do this I get a php error:

    Wrong parameter count for nl2br() in /home/guru54gt5/public_html/im/expert_disp.php on line 30

    I am using php 5.2

    So what did I mis-understand ?
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    PHP Code:
    See http://php.net/manual/en/function.nl2br.php#73440
    Digitalocean Cloud Hosting (Referral link - get $10 free credit) Fameco


    • #3
      You will have to use the method above. Using what you tried only works on PHP 5.3.0+

      It helps if you read the changelog.
      Originally posted by php.net

      Version Description
      5.3.0 Added the optional is_xhtml parameter.
      4.0.5 nl2br() is now XHTML compliant. All older versions will return string with '<br>' inserted before newlines instead of '<br />'.
      I would actually use this instead
      PHP Code:
      function nl2br2($text)
      This way you get all possible new line characters.
      Last edited by _Aerospace_Eng_; Apr 9, 2009, 09:09 AM.
      ||||If you are getting paid to do a job, don't ask for help on it!||||


      • #4
        I agree with aerospace

        if you make it a function, you can use it without finding the code again