Forum Moderators: coopster

Message Too Old, No Replies

$_POST of empty vs 0 value

         

elazary

3:51 pm on Dec 12, 2004 (gmt 0)

10+ Year Member



working on LINUX I found that both empty($_POST['foo']) where $foo = 0 or &foo = empty gives me TRUE.
I.e. I can not distingush between 0 and empty value - I need it for the text box value.
What is the solution?

Adrian2k4

4:00 pm on Dec 12, 2004 (gmt 0)

10+ Year Member



this is from the php manual: (http://ch2.php.net/empty)
"empty() returns FALSE if var has a non-empty and non-zero value. In otherwords, "", 0, "0", NULL, FALSE, array(), and var $var; are all considered empty. In PHP 4 and earlier, objects with empty properties are considered empty. This is not the case in PHP 5. TRUE is returned if var is empty."

i'm not if this works... try something like "is_null" "is_int()" or "isset()".

or

test the following:
<?php
echo strlen('0');
echo strlen('');
echo strlen(NULL);
?>

regards
adrian

mincklerstraat

4:02 pm on Dec 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi elazary, welcome to webmasterworld [webmasterworld.com]. Have a look at
isset()
[be.php.net]

<edit>ah, Adrian2K4: Jinx!</edit>

elazary

4:19 pm on Dec 12, 2004 (gmt 0)

10+ Year Member



thanks, guys
strlen works, all other do not help
elazar

coopster

1:39 pm on Dec 13, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



As has been stated, empty() [php.net] returns FALSE only if the variable being checked has a non-empty and non-zero value. You could always use exact Comparison Operators [php.net] to check the value.