What are the best practices for handling user input securely in PHP scripts?

When handling user input in PHP scripts, it is essential to validate and sanitize the input to prevent security vulnerabilities such as SQL injection or cross-site scripting attacks. One way to do this is by using PHP functions like filter_input() or htmlspecialchars() to sanitize user input before using it in your script. Example:

```php
$userInput = filter_input(INPUT_POST, 'user_input', FILTER_SANITIZE_STRING);
echo "User input: " . $userInput;
```

In the above code snippet, the user input from a POST request is sanitized using the FILTER_SANITIZE_STRING filter before being echoed to the output. This helps prevent any malicious input from being executed in the script.