What best practices should be followed when handling user input that may contain line breaks in PHP?

When handling user input that may contain line breaks in PHP, it is important to sanitize the input to prevent any potential security vulnerabilities, such as SQL injection or cross-site scripting attacks. One common approach is to use the `nl2br()` function to convert line breaks to HTML `<br>` tags before displaying the input on a webpage.

$userInput = $_POST[&#039;user_input&#039;];
$sanitizedInput = nl2br(htmlspecialchars($userInput));
echo $sanitizedInput;