What are the best practices for handling slashes in PHP to ensure security and prevent errors in code execution?

When handling user input or file paths in PHP, it's important to properly sanitize and escape any slashes to prevent security vulnerabilities such as directory traversal attacks. One way to do this is by using the `addslashes()` function to escape the slashes before using the input in your code. This helps ensure that the input is treated as data rather than executable code.

$user_input = $_POST['user_input'];
$escaped_input = addslashes($user_input);

// Now you can safely use $escaped_input in your code