What are some common pitfalls when using wildcards like * in PHP comparisons?

When using wildcards like * in PHP comparisons, one common pitfall is forgetting to properly escape or sanitize user input before using it in the comparison. This can lead to unexpected behavior or security vulnerabilities. To solve this issue, always sanitize and validate user input before using it in wildcard comparisons.

$user_input = $_GET['input']; // Assuming user input is coming from a form field

// Sanitize and validate user input
$clean_input = filter_var($user_input, FILTER_SANITIZE_STRING);

// Perform wildcard comparison
if (fnmatch('hello*', $clean_input)) {
    echo "Input matches pattern 'hello*'";
} else {
    echo "Input does not match pattern 'hello*'";
}