From: Sam Smith on
$string = 'text with no newline';
$pattern = '/(.*)/';
$replacement = '${1}XX\nNext line';
$string = preg_replace($pattern, $replacement, $string);
echo $string;

Outputs:
text with no newlineXX\nNext line
Instead of:
text with no newlineXX
Next line

How does one insert a newline with preg_replace?

Thanks
From: Shawn McKenzie on
On 06/02/2010 04:28 PM, Sam Smith wrote:
> $string = 'text with no newline';
> $pattern = '/(.*)/';
> $replacement = '${1}XX\nNext line';
> $string = preg_replace($pattern, $replacement, $string);
> echo $string;
>
> Outputs:
> text with no newlineXX\nNext line
> Instead of:
> text with no newlineXX
> Next line
>
> How does one insert a newline with preg_replace?
>
> Thanks

http://us.php.net/manual/en/language.types.string.php

Pay attention to single and double.

--
Thanks!
-Shawn
http://www.spidean.com