Forum Moderators: coopster

Message Too Old, No Replies

Replaceing a new line with <br>

         

mehh

1:15 pm on Aug 8, 2006 (gmt 0)

10+ Year Member



I have a textarea input to one of my scripts and it will not work if I have the input on more than one line so i have tryed to replace the new line with <br /> so it still looks as if there is a line break but there is not. but every time i try it i always get a new line and then <br /> rather than the <br /> without the new line.
Can someone please help.
Functions i have tryed so far( you never know they might help):

ereg_replace("\n","<br />",$input)
nl2br($input)
str_replace("\n", "<br />", $str);
implode("<br />",explode("\n",$input))

dreamcatcher

2:12 pm on Aug 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi mehh,

The nl2br [uk2.php.net] function should do the trick.

Failing that you need to use the syntax for a carriage return, rather than a new line. str_replace [uk2.php.net] will do just fine.

$data = str_replace("\r\n", "<br />", $data);

dc

mehh

2:29 pm on Aug 8, 2006 (gmt 0)

10+ Year Member



Thankyou dreamcatcher! its working now.