View Full Version : Line breaks in textarea

10-15-2004, 10:32 PM
Hi.. I have problem with a textarea in a form I made... line breaks are output as \r\n, and I can't seem to fix it.

I tried nl2br() on the string, but it just returns the same string, it's not working like it should for some reason.

I also tried doing $str = str_replace("\r\n","<br />",$str); and this, for some reason, is not working either.

I tried doing this to the string variable both before insertion to the database, and also after retrieval, at the time it's gonna be displayed, and nothing works... I keep getting the \r\n.

What can be going on here?

10-15-2004, 10:50 PM
$str = preg_replace("(\r\n|\r|\n)","<br />",$str);

Use preg_replace instead of str_replace. Depending on the Operating System the line break could be a \r\n, a \r, or a \n

The nl2br() should have worked...as it looks for any of the three...strange.