What are the best practices for managing text input with line breaks in PHP forms?

When managing text input with line breaks in PHP forms, it's important to properly handle the line breaks to ensure they are displayed correctly when the form data is saved or displayed. One common approach is to use the nl2br() function to convert newline characters to HTML line breaks <br>. This function allows the text to be displayed with proper line breaks in HTML.

// Retrieve text input from form
$text = $_POST[&#039;text&#039;];

// Convert newline characters to HTML line breaks
$clean_text = nl2br($text);

// Save or display the cleaned text with line breaks
echo $clean_text;