POSTed 值永远不会为空?
我需要进行分配来检查分配给变量的某些 html 表单字段(type =“text”)是否为空。我发现 is_null() 没有检测到分配了空字段的变量,但 empty() 可以。
POSTed 值不为空的原因是什么?另外,isset() 会是更好的选择吗?
I am required for an assignment to check if certain html form fields (type="text") assigned to variables are null. I'm finding that is_null() is not detecting variables to which empty fields are assigned, but empty() does.
What is the reason why POSTed values are not null? Also, would isset() be a better choice for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的网页上未设置输入字段,则浏览器根本不会发送该输入字段。因此你没有看到 null,你没有看到任何东西到达。
If an input field is not set on your web page, the browser will not send it at all. Therefore you are not seeing null, you are not seeing anything arrive.
以下内容应该适合您。如果存在与您的数组键匹配的表单元素,它将被设置为空字符串,如果表单元素不存在,isset 将返回 false。
The following should work for you. If there is form element that matches your array key, it will be set to an empty string, if the form element doesn't exist isset will return false.
因为从数据的角度来看,空值在语义上比 null 更有意义,而 null 更像是一个运行时编程概念。实际上,空值不能以与平台和编程语言无关的方式通过网络进行编组。
Because an empty value is semantically more sensible from a data point of view than a null, which is more of a runtime, programming concept. A null value actually cannot be marshalled across the wire in a platform and programming language agnostic fashion.