What is the best practice for handling line breaks in user input in PHP before storing it in a database?

When handling user input in PHP before storing it in a database, it is important to properly handle line breaks to prevent any potential issues with formatting or SQL injection attacks. One common approach is to use the PHP function `mysqli_real_escape_string()` to escape special characters, including line breaks, before inserting the input into the database.

// Assuming $input contains the user input
$escaped_input = mysqli_real_escape_string($connection, $input);
// Now $escaped_input can be safely inserted into the database