Re: Replacing newlines (\n) with smething else

From: Date: Sun, 13 Jul 2003 21:27:04 +0000
Subject: Re: Replacing newlines (\n) with smething else
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-155023@lists.php.net to get a copy of this message
Perhaps. When getting text from a form field, what is substituted for a newline (i.e. when someone hits enter). Jason On Sun, 2003-07-13 at 17:21, David Otton wrote: > On 13 Jul 2003 17:01:24 -0400, you wrote: > > >I'm trying to replace newlines with something else. For this example > >I'll use <br> as the thing to replace a newline with. This is what I > >tried and it doesn't work. > > nl2br() in the specific case > > >$article = str_replace("\n", "<br>", $article); > > > >What am I doing wrong? $article is the string to replace the newlines > >in. I tried this with a period and that works as expected. Can I not > >replace newlines this way? > > But in the general case, your code looks ok to me. > > echo (str_replace("\n", "<br>", "foo\nbar")); > > returns "foo<br>bar" here. Maybe $article doesn't contain what you think > it > does? > > (BTW, I prefer to replace "\n" with "<br>\n", but that's just a > style > thing.) >

« previous php.general (#155023) next »