Are there best practices for handling line breaks or formatting issues in PHP output?

When outputting text in PHP, line breaks and formatting can sometimes cause issues such as extra spaces or unexpected line breaks. To handle this, you can use the PHP function `nl2br()` to convert newline characters to HTML line breaks, ensuring proper formatting in the output.

$text = "Hello\nWorld!";
echo nl2br($text);