Search code examples
phpisset

Trying to find whether my PHP variable has any content


Hi I have a PHP variable called Keyword, what I am trying to find out is if there is any content in the variable.

 if (isset($keyword)) {

Using the above code it returns values that are blank.


Solution

  • try

    trim($keyword);
    if (isset($keyword) && !empty($keyword)) {
        // Code here
    }
    

    Edit:

    This fixed your problem because you had trailing whitespace in your variable. even though it appeared empty it still had a space or carriage return.