In PHP form submissions, how can the issue of the "enter" key being replaced by a space be resolved to ensure proper formatting of user input?

When a form is submitted in PHP, the "enter" key is often replaced by a space in the input data. To resolve this issue and ensure proper formatting of user input, you can use the `nl2br()` function in PHP. This function converts newlines in a string to HTML line breaks, allowing the entered text to be displayed with proper line breaks.

// Get the form input data
$user_input = $_POST['user_input'];

// Replace newlines with HTML line breaks
$formatted_input = nl2br($user_input);

// Display the formatted input
echo $formatted_input;