What is the function nl2br in PHP and how can it be used to address the problem of preserving line breaks?
Preserving line breaks in PHP can be a challenge when displaying text that includes newline characters. The nl2br function in PHP is used to convert newline characters (\n) to HTML line breaks (<br>) so that the line breaks are preserved when rendering the text on a webpage.
$text = "Hello\nWorld!";
echo nl2br($text);
```
In this code snippet, the variable $text contains the string "Hello\nWorld!". When the nl2br function is applied to $text and echoed to the output, the newline character (\n) is converted to an HTML line break (<br>), resulting in the output:
```
Hello
World!