What are best practices for handling user input validation in PHP to prevent issues like "00" and "-1"?

When handling user input validation in PHP, it is important to sanitize and validate the input to prevent issues like "00" and "-1". One way to address this is by using PHP's built-in functions like `filter_var()` with the `FILTER_VALIDATE_INT` filter to ensure the input is a valid integer.

// Validate user input to prevent issues like "00" and "-1"
$userInput = $_POST['input'];

// Check if input is a valid integer greater than or equal to 0
if (filter_var($userInput, FILTER_VALIDATE_INT) === false || $userInput < 0) {
    // Handle invalid input
    echo "Invalid input. Please enter a positive integer.";
} else {
    // Proceed with valid input
    echo "Valid input: " . $userInput;
}