isset is the proper choice here -- empty is only intended to examine a known variable to see if it is "emptyish". According to the docs
The following things are considered to be empty:
"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
var $var; (a variable declared, but without a value in a class)
What it doesn't say is how it treats array members that are not defined. A comment on the docs page gives us some insight from testing: http://www.php.net/manual/en/function.empty.php#105722
Note that checking the existence of a subkey of an array when that
subkey does not exist but the parent does and is a string will return
false for empty.
Whereas isset (docs) is designed to "Determine if a variable is set and is not NULL. " -- exactly what you're after. Thus, your code ends up looking like this:
// check the length, too, to avoid zero-length strings
if(!isset($_POST["example"]) || strlen(trim($_POST["example"])) < 1) {
echo "You need to enter any text to example box.";
} else {
// handle form submission
}
Documentation
PHP isset - http://php.net/manual/en/function.isset.php
PHP empty - http://www.php.net/manual/en/function.empty.php
More reading - http://virendrachandak.wordpress.com/2012/01/21/php-isset-vs-empty-vs-is_null/