How can PHP developers ensure proper formatting for user input that requires line breaks?
When dealing with user input that requires line breaks, PHP developers can ensure proper formatting by using the nl2br() function. This function converts newlines (\n) in a string to HTML line breaks (<br>) so that the text is displayed correctly in the browser.
$user_input = "This is a text with \n line breaks.";
$formatted_input = nl2br($user_input);
echo $formatted_input;