Dive into the details of PHP nl2br of formatted output

  • 2020-06-07 04:06:57
  • OfStack

The nl2br() function converts a newline character in a string to the HTML newline symbol

<?php 
$str = " In recent days 1 It was raining and I was so sad  
 I couldn't play the ball and my shoes were wet. "; 
echo $str; 
echo "<br />"; 
echo nl2br($str); 
?>

Output results:

 In recent days 1 It was raining and I was so sad that I couldn't play the ball and my shoes were wet. 
 In recent days 1 It was raining and I was so sad that I couldn't play the ball and my shoes were wet. 

Attached: In-depth Discussion" & lt;br / & gt;" What's the difference between \r\n?

Related articles: