Are there any specific PHP functions or methods that can help with maintaining text formatting when displaying user input?

When displaying user input, it's important to maintain text formatting to ensure that the content appears as intended. One way to achieve this is by using the PHP `nl2br()` function, which converts newline characters into HTML line breaks. This function can be used to preserve line breaks and maintain the formatting of user input when displaying it on a webpage.

$userInput = "Hello\nWorld!";
echo nl2br($userInput);