Re: Replacing newlines (\n) with smething else
| From: | David Otton | Date: | Sun, 13 Jul 2003 21:21:34 +0000 |
| Subject: | Re: Replacing newlines (\n) with smething else | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-155022@lists.php.net to get a copy of this message | ||
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.)