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! Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.