SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Internet Business Optimizer KCgame's Avatar
    Join Date
    Mar 2005
    Location
    Singapore
    Posts
    928
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Unable to detect \n for output on screen

    Hi all,

    I am using text field for my message input by the user. The problem is that the message displayed is always in a straight line..(it does not detect any newlines even if user keys in )

    For example, User input the following in a text field:
    Code:
    Hello,
    Nice to meet you.
    When I query from the database (Text format), it shows
    Code:
    Hello, Nice to meet you
    How can I make it so that it can detect the newline(s) entered by the users in the textfield?

    Any help / advice will be greatly appreciated. Thank you.

  2. #2
    SitePoint Guru
    Join Date
    Feb 2004
    Location
    Oregon
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    uses php to replace the \n with a <br> tag.

    $var = str_replace("\r|\n|\r\n","<br />", $_POST['foo']);
    success is not by chance, it is by choice.

  3. #3
    Internet Business Optimizer KCgame's Avatar
    Join Date
    Mar 2005
    Location
    Singapore
    Posts
    928
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Sahajin
    uses php to replace the \n with a <br> tag.

    $var = str_replace("\r|\n|\r\n","<br />", $_POST['foo']);
    Hi Sahajin, thanks for the help^^
    However, it still display the old one line statement..Do i have to do anything in getting out the data from the database?

    Currently I just pull it directly from the db..

  4. #4
    SitePoint Guru
    Join Date
    Feb 2004
    Location
    Oregon
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can do it either way. as long as the \n is in the db field you can do it when it comes out too.

    I prefer it when it goes in but up to you.

    if it is already there then do ti when it comes out. or update the db and change al of the \n to a break tag and then start inserting it with the break tag.
    success is not by chance, it is by choice.


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
  •