Q:

Why a function checking if a string is empty always returns true?

I have a function isNotEmpty which returns true if the string is not empty and false if the string is empty. I've found out that it is not working if I pass an empty string through it. 
function isNotEmpty($input) 
{
    $strTemp = $input;
    $strTemp = trim($strTemp);

    if(strTemp != '') //Also tried this "if(strlen($strTemp) > 0)"
    {
         return true;
    }

    return false;
}

The validation of the string using isNotEmpty is done:
if(isNotEmpty($userinput['phoneNumber']))
{
    //validate the phone number
}
else
{
    echo "Phone number not entered<br/>";
}

If the string is empty the else doesn't execute, I don't understand why, can someone please shed some light on this please.

A:

Simple problem actually. Change:
if (strTemp != '')

to 
if ($strTemp != '')

Arguably you may also want to change it to:
if ($strTemp !== '')

since != '' will return true if you pass is numeric 0 and a few other cases due to PHP's automatic type conversion.
You should not use the built-in empty() function for this; see comments and the PHP type comparison tables.

A:

PHP have a built in function called empty()
the test is done by typing 
if(empty($string)){...}
Reference php.net : php empty

A:

I always use a regular expression for checking for an empty string, dating back to CGI/Perl days, and also with Javascript, so why not with PHP as well, e.g. (albeit untested)
return preg_match('/\S/', $input);

Where \S represents any non-whitespace character

