$string = "This is\na test.\n"; echo nl2br($string);
This is
a test.
// Retrieve text from database $text = $row['text']; // Convert new line characters to HTML line breaks $text = nl2br($text); // Display text on web page echo $text;The nl2br function is part of PHP's core functionality and does not require any package or library to be installed.