The input is from a file. I'm using this code:
$inputText = "a\nb\nc\nd";
$outputText = str_replace(PHP_EOL, ("<br />".PHP_EOL), $inputText);
The output is:
a
<br />b
<br />c
<br />d
<br />
but I need:
a<br />
b<br />
c<br />
d<br />
Can somebody help me pls?
Just use nl2br().
This will do all the work for you. No need for manual replacing.
$outputText = nl2br($inputText);
Just try with:
$outputText = str_replace("\n", "<br />\n", $inputText) . '<br />';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With