What alternative methods can be used for escaping input in PHP?

When accepting user input in PHP, it is important to escape the input to prevent potential security vulnerabilities such as SQL injection or cross-site scripting attacks. One common method for escaping input is using the `htmlspecialchars()` function to convert special characters to HTML entities. Another method is using prepared statements when interacting with a database to prevent SQL injection attacks.

// Escaping user input using htmlspecialchars()
$userInput = '<script>alert("XSS attack")</script>';
$escapedInput = htmlspecialchars($userInput, ENT_QUOTES, 'UTF-8');
echo $escapedInput;