How can PHP developers ensure that line breaks are maintained when processing user input from textareas?

When processing user input from textareas in PHP, developers can ensure that line breaks are maintained by using the nl2br() function. This function converts newlines in a string to HTML line breaks, allowing the text to be displayed with proper formatting on a webpage.

$user_input = $_POST['textarea_input'];
$user_input_with_line_breaks = nl2br($user_input);

echo $user_input_with_line_breaks;