Helminthophobe Posted October 25, 2007 Share Posted October 25, 2007 Can I use empty() to check to see if variables actually have data? Basically I want the script or something to check to see if there is data in the variables. If there is no data, give the user some instructions on writing some data (link to a form or admin panel). If there is data, then continue with writing to the database. Any help would be greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/74734-solved-checking-for-empty-variables/ Share on other sites More sharing options...
kenrbnsn Posted October 25, 2007 Share Posted October 25, 2007 I don't use the empty() function on strings, since it can return a false positive when the string consists of the a single zero character. I use <?php if (strlen(trim($str)) == 0) echo 'The variable $str is empty'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/74734-solved-checking-for-empty-variables/#findComment-377791 Share on other sites More sharing options...
ThYGrEaTCoDeR201 Posted October 25, 2007 Share Posted October 25, 2007 Also remember that a whitespace in a variable can be a true value. Example: $var1 = ""; this will be empty $var2 = " "; this is the same as 1 Link to comment https://forums.phpfreaks.com/topic/74734-solved-checking-for-empty-variables/#findComment-377806 Share on other sites More sharing options...
Helminthophobe Posted October 25, 2007 Author Share Posted October 25, 2007 Awesome! Thanks for the quick replies. This should help me out a lot. Link to comment https://forums.phpfreaks.com/topic/74734-solved-checking-for-empty-variables/#findComment-377807 Share on other sites More sharing options...
Elminster Posted October 25, 2007 Share Posted October 25, 2007 This could be helpful too: http://www.php.net/manual/en/types.comparisons.php Link to comment https://forums.phpfreaks.com/topic/74734-solved-checking-for-empty-variables/#findComment-377837 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.