How can PHP be used to replace line breaks with <br> tags in a text string?

When displaying text from a database or user input in HTML, line breaks are often represented by "\n" characters. To display these line breaks correctly in the browser, we can use the PHP `nl2br()` function, which replaces newline characters with HTML `<br>` tags. This function will convert all line breaks in a text string to `<br>` tags, allowing the text to be displayed with proper line breaks in HTML.

&lt;?php
$text = &quot;Hello\nWorld!&quot;;
echo nl2br($text);
?&gt;