Please help with a code

Discussion in 'PHP' started by JEET, Apr 23, 2006.

  1. #1
    Hi guys,
    I have some text in a variable, something like:

    $bbtext = $_REQUEST['bbcodetext'];
    ( pulled from a textarea form)

    The text in this is:
    "This is line 1,
    This is line 2,
    This is line 3,
    and so on..."

    The problem is that when I print this to a blank file on my server, the lines are joined, something like:

    "This is line 1,This is line 2,This is line 3,and so on..."

    Is it possible to add a "<br>" at the end of each line and then store it in the same variable before sending it to the file? If so, then please help.

    Thank you
    jeet
     
    JEET, Apr 23, 2006 IP
  2. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #2
    text editors don't understand the <br> tag.

    you will need to insert a \n (newline character) anywhere you want to have a line break...

    so you should write the following to file:
    "This is line 1,\nThis is line 2,\nThis is line 3,\nand so on..."
     
    daboss, Apr 23, 2006 IP
  3. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I was under the impression that the textarea sent the newline (\n) characters with its text.

    That would mean that you don't need to insert any newline characters: server side, you just need to replace any instance of '\n' with '<br>'.
     
    TwistMyArm, Apr 23, 2006 IP
  4. av1

    av1 Active Member

    Messages:
    168
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #4
    try this $bbtext = nl2br($_REQUEST['bbcodetext']);
    instead your source code line
     
    av1, Apr 23, 2006 IP
  5. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #5
    Very cool!!! Totally works...
    It's just when I added an " ' ", a back slash is displayed before that. But I can be careful about that.
    Thanks so much.
    Bye
    jeet
     
    JEET, Apr 23, 2006 IP