Reputation: 19
I have a textarea , with some text and some enters. but I want to write all of the text into 1 line of a file in php. with <br>
instead of enters. How can I do that?
Upvotes: 0
Views: 62
Reputation: 1794
You can either use nl2br or str_replace function
Sample text
<?php
$text = 'line1
line2
line3
line4
line5';
?>
with nl2br
<?php
echo nl2br( $text );
/**
line1<br />
line2<br />
line3<br />
line4<br />
line5
**/
?>
with str_replace
<?php
echo str_replace( PHP_EOL, "<br />", $text );
/**
line1<br />line2<br />line3<br />line4<br />line5
**/
?>
Upvotes: 0
Reputation: 75649
I think you want to use nl2br if you are trying to replace all the newlines with <br>
.
Upvotes: 2