php check if an POST item is given a value

1596阅读 1评论2011-04-10 neobilly
分类:系统运维

when a form is submited,the item which is not set a value is given the value of "";
so you can not use isset($_POST["name"]) to determine if the item is set a value,
because the isset() can check if a variable is NULL( not "\0") or isset,
so you should use if($_POST["name"] != "") instead to get things done.

判断一个控件是否被赋值的时候,用isset()是不行的,因为isset
判断的依据是这个控件是不是NULL,而被POST的value,如果没被设置
那么它的值是"",而"" != NULL,所以应该用if($_POST["name"] != "")
来进行
toy example:
php -r '$var = ""; if(isset($var)){echo "\"\" != NULL\n";}'

上一篇:openSuSE 安装emacs 出现emacs_program 依赖的
下一篇:使用LWP 抓取网页

文章评论