What function can be used in PHP to insert line breaks before all newlines in a string?

To insert line breaks before all newlines in a string in PHP, you can use the `nl2br()` function. This function converts all newlines in a string to HTML line breaks `<br>`. This is useful when you want to display text with line breaks in an HTML document.

$string = &quot;Hello\nWorld!&quot;;
echo nl2br($string);