Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting mad with my guestbook coding..

    How can i turn the "new lines" into "<br>"?, because i'm using javascript functions to generate the message, so in the function i can't use any newline, just <br>. for example:

    this doesn't work
    <script>guestmessage("55", "9:01:01am - Sun, September 28, 2003.", "Exodus", "http://www.codingforums.com", "hello everyone
    <br>bla bla bla bla
    <br>bla bla bal
    <br>lbalbalbal
    <br>")</script>

    this will work
    <script>guestmessage("55", "9:01:01am - Sun, September 28, 2003.", "Exodus", "http://www.codingforums.com", "hello everyone<br>bla bla bla bla<br>bla bla bal<br>lbalbalbal<br>")</script>

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Since the code you just posted is all JavaScript, I'm not sure where your actual PHP question is? If you want to know how to turn linebreaks into <br /> tags, have a look at http://www.php.net/nl2br
    De gustibus non est disputandum.

  • #3
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thx to everyone that had helped me

    I had finally found the way to do what i wanted to do

    the code i wanted was

    $text = str_replace ( "\r\n", "<BR>", $text );

    which transforms my multi-line text in a single line of text, for example

    "Hello Everyone
    Thanx for helping
    This is a great forum"

    into

    "Hello Everyone<br>Thanx for helping<br>This is a great forum"

    At the first time i had tried just with "\n", like this
    $text = str_replace ( "\n", "<BR>", $text );
    which gave me this result

    "Hello Everyone
    <br>Thanx for helping
    <br>This is a great forum"


    I hope this could help any1.

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    the function mordred posted nl2br() does exactly what you just posted.

    $text = nl2br($text);


  •  

    Posting Permissions

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