I just want to replace "\n" characters to new line in a string using php, like that :
string 'foo\n\nbar'
to
string 'foo
bar`
Anybody have an idea ? Thanks.
use str_replace('\n', PHP_EOL, 'foo\n\nbar');
<?php
header('Content-Type: text/plain');
$string = 'foo\n\nbar';
$string = str_replace('\n', PHP_EOL, $string);
echo $string;
?>
Shows:
foo
bar
nl2br option to your answer in the case that the text is to be displayed as HTMLnl2br is already mentioned by chandresh_cool.you can always Use
nl2br
function