SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: \n

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    \n

    When I add "\n" in my text it does not seem to matter to the browser. I am using an editor which recognizes it as a new line, but when I view the file in IE it does not.

    Wazzup?

  2. #2
    SitePoint Addict
    Join Date
    Aug 2000
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What kind of file is it? HTML, PHP, CGI, Javascript?

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    \n

    sorry - I am using php

  4. #4
    SitePoint Addict
    Join Date
    Aug 2000
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps you can post a bit of your code to see.

    There's no reason that I can see why it shouldn't count that as a new line unless it's coded wrong or perhaps the "Editor" is doing something to the code.

    Example:
    Code:
    <?
      print( "this is some text\n" );
      print( "and this is some more\n" );
      print( "\n" );
      print( "And again" );
    ?>
    SHOULD return:

    this is some text
    and this is some more

    And again





    HTH

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is what I see in Editor Window:

    X-Powered-By: PHP/4.1.0
    Content-type: text/html

    this is some text
    and this is some more

    And again
    Here is what I see in Browser (IE5.5)
    this is some text and this is some more And again

  6. #6
    SitePoint Zealot Tiggy's Avatar
    Join Date
    Mar 2002
    Location
    Lancashire, UK
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The IE5 code sample, is that what you see on the screen or when you view the source? If your source code for the page has the newlines in the right place then you don't need to do anything - you should use HTML/XHTML to make your line breaks appear on the web page.

  7. #7
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by OpticChild
    Here is what I see in Browser (IE5.5)
    what you see in your browser is html... you need to use line breaks <br /> to add newlines... \n is only for adding new lines to your html code

  8. #8
    SitePoint Enthusiast z00om's Avatar
    Join Date
    Dec 2001
    Location
    California
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, exactly. a "\n" is a newline, which only makes any difference to a text file, not HTML. for HTML, you should do something like this....

    $var = eregi_replace("\\n","\\n<br>\\n",$var);

    just tell it to replace all \n's with a <br>!

    example:

    $var = "Hello,\n\nhow are you?";

    TEXT OUTPUT--W/O REPLACEMENT
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Hello

    how are you?
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    TEXT OUTPUT--W/ REPLACEMENT
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Hello
    <br>
    how are you?
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    HTML OUTPUT--W/O REPLACEMENT
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Hellohow are you?
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    HTML OUTPUT--W/ REPLACEMENT
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Hello

    how are you?
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

    just to... further my example, the page you're having trouble with, goto view source, you should see it THERE how it you want it! but HTML don't care about spaces, tabs, and newlines.... it cares about HTML!
    [z00om : home]
    [z00om@hotmail.com]
    [z00om : aim]
    [77968493 : icq]

  9. #9
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by z00om
    $var = eregi_replace("\\n","\\n<br>\\n",$var);
    remember, there is no need for the horrendous D) ereg function. just use nl2br(). many, many times faster.

    PHP Code:
    $txt nl2br($txt); 
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  10. #10
    SitePoint Enthusiast z00om's Avatar
    Join Date
    Dec 2001
    Location
    California
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whoa! I never even know about that! Thanks a lot!
    [z00om : home]
    [z00om@hotmail.com]
    [z00om : aim]
    [77968493 : icq]


Bookmarks

Posting Permissions

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