What is the recommended approach for handling line breaks in PHP text fields?

When handling text fields in PHP, it's important to properly handle line breaks to ensure consistent formatting across different platforms. One recommended approach is to use the PHP function nl2br() which converts newline characters to HTML line breaks <br>. This allows the text to be displayed with line breaks in HTML without affecting the underlying data.

$text = &quot;This is a text with line breaks.\nLine 1\nLine 2&quot;;
$formatted_text = nl2br($text);
echo $formatted_text;