String myStr1 = "Jack Sparrow"; String myStr2 = ""; First, it checks to see if the variable exists. You can use the strict equality operator (===) to check whether a string is empty or not. empty — Determine whether a variable is empty. Let’s say we have the following strings. But the only difference is !empty() function will not generate any warning or e-notice when the variable does not exists. Required fields are marked * Comment. In other words, it will return true if the variable is an empty string, false, array(), NULL, “0?, 0, and an unset variable. Dinesh says: November 4, 2020 at 11:12 am Thanks Anita. I will explain further in the later part of this tutorial, first syntax and live examples of using the empty function. Reason to check both function: The isset() and !empty() functions are similar and both will return the same results. The empty() function returns true if a string is empty… Your email address will not be published. Possible Duplicate: If string only contains spaces? empty() From PHP Manual – empty():. The PHP function empty is often used to check if a particular variable is empty or not (duh). I want to check if the entire string is ONLY white space… As noted earlier, is_string() returns false on an object that has a __toString() method. Particularly, in regards to user-submitted string … Name * When use ==, as you did, PHP treats NULL, false, 0, the empty string, and empty arrays as equal. To add to @BJorn and @SeanPatrickFloyd The Guava way to do this is: Strings.nullToEmpty(str).isEmpty(); // or Strings.isNullOrEmpty(str); Commons Lang is more readable at times but I have been slowly relying more on Guava plus sometimes Commons Lang is confusing when it comes to isBlank() (as in what is whitespace or not).. Guava’s version of Commons Lang isBlank … The PHP empty() function used to check whether the string is empty or not. PHP empty() function. share | improve this answer | follow | edited Dec 11 '19 at 23:39 It is very useful. Leave a Reply Cancel reply. However, there is a bit of caveat that you should be aware of. In PHP the empty() function return true if the variable has empty or zero value and it return false if string has non-empty or non-zero value. To check whether a given string is empty or not, we can use the built-in empty() function in PHP language. The comparsion str === "" will only return true if the data type of the value is string and it is not empty, otherwise return false as demonstrated in the following example: The PHP empty function is used to determine if a variable is empty or not. PHP empty() function syntax: empty(“string”); PHP example of empty… If it does exist, then it checks to see if the variable is a “falsey” value. Here is a simple way to do a check that will work: