View Full Version : Getting mad with my guestbook coding..

09-28-2003, 04:25 PM
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

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>

09-28-2003, 07:04 PM
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

09-28-2003, 07:18 PM
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"


"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.

09-28-2003, 08:07 PM
the function mordred posted nl2br() does exactly what you just posted.

$text = nl2br($text);

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum