What alternatives to mysql_escape_string can be used to escape special characters in PHP without affecting line breaks?

When using mysql_escape_string to escape special characters in PHP, line breaks are also affected, which can lead to formatting issues in text. To avoid this problem, one alternative method is to use the mysqli_real_escape_string function, which performs the same task of escaping special characters without affecting line breaks.

// Using mysqli_real_escape_string to escape special characters without affecting line breaks
$mysqli = new mysqli("localhost", "username", "password", "database");

// Assuming $input contains the user input that needs to be escaped
$escaped_input = $mysqli->real_escape_string($input);

// Now $escaped_input can be safely used in SQL queries without affecting line breaks