How can you ensure that a variable is considered empty in PHP, even if it contains whitespace?

In PHP, a variable containing whitespace may not be considered empty when using functions like empty() or isset(). To ensure that a variable is considered empty even if it contains whitespace, you can use the trim() function to remove any leading or trailing whitespace before checking its emptiness.

$var = "   "; // variable containing whitespace

// Check if variable is empty after trimming whitespace
if (empty(trim($var))) {
    echo "Variable is empty";
} else {
    echo "Variable is not empty";
}