How do you check if a string is empty in PHP with Example?

Hello Friends Today, through this tutorial, I will tell you How do you check if a string is empty using PHP With Example? In PHP, you can check if a string is empty using several methods. Here are a few common ones with examples:

1. Using empty() function:

$string = ""; // Empty string
if (empty($string)) {
echo "String is empty.";
} else {
echo "String is not empty.";
}

2. Using strlen() function:

$string = ""; // Empty string
if (strlen($string) == 0) {
echo "String is empty.";
} else {
echo "String is not empty.";
}

3. Using comparison with an empty string:

$string = ""; // Empty string
if ($string === "") {
echo "String is empty.";
} else {
echo "String is not empty.";
}

All these methods will output “String is empty.” since the string `$string` is empty.