Are there best practices for handling user data storage in PHP to avoid issues with newline characters?

When storing user data in PHP, it is important to properly sanitize input to avoid issues with newline characters. One common approach is to use the `trim()` function to remove any leading or trailing whitespace, including newline characters, before storing the data in a database or file.

// Sanitize user input to remove newline characters
$userInput = trim($_POST['user_input']);

// Store sanitized user input in a database or file
// Example: storing in a MySQL database
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');
$stmt = $pdo->prepare("INSERT INTO mytable (user_input) VALUES (:user_input)");
$stmt->bindParam(':user_input', $userInput);
$stmt->execute();