Forum Moderators: coopster

Message Too Old, No Replies

Detecting a carriage return

         

xeonaphobe

2:47 am on Feb 17, 2005 (gmt 0)

10+ Year Member



Hi there,

I'm having another problem with my flat file blog that I hope you can help me with. I'm trying to set it so that whenever a user submits a comment, the script will automatically detect when the user has used a line break. At the moment, the script seems to just ignore this when displaying the comments and posts one large paragraph.

Any ideas as to how I can get around this?

Thanks very much in advance :)
Neil

xeonaphobe

3:03 am on Feb 17, 2005 (gmt 0)

10+ Year Member



Right, i've read on another forum that using Javascript is one way to solve the problem. However, i'd still rather deal with it within my add comment php script. I take it if there is a way of doing it with php, i'd be better off using the php method?

To be honest, if I did go with the JS method, i'm not entirely sure how i'd set the php variable to the modified JS one without having to submit it again...

Cheers,
Neil

jamesa

3:48 am on Feb 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What you need is PHP's nl2br function. Works like this:

echo nl2br($somevar);

or
echo nl2br("some text");

It add html break tags to all the linebreaks. See: [us2.php.net ]