我应该在哪里使用isset()和!empty() [英] In where shall I use isset() and !empty()

查看:107
本文介绍了我应该在哪里使用isset()和!empty()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在某处读到isset()函数将空字符串视为TRUE,因此isset()并不是从HTML表单验证文本输入和文本框的有效方法.

I read somewhere that the isset() function treats an empty string as TRUE, therefore isset() is not an effective way to validate text inputs and text boxes from a HTML form.

因此,您可以使用empty()来检查用户是否键入了某些内容.

So you can use empty() to check that a user typed something.

  1. isset()函数是否将空字符串视为TRUE是真的吗?

  1. Is it true that the isset() function treats an empty string as TRUE?

那我应该在什么情况下使用isset()?我是否应该始终使用!empty()检查是否存在某些东西?

Then in which situations should I use isset()? Should I always use !empty() to check if there is something?

例如代替

if(isset($_GET['gender']))...

使用此

if(!empty($_GET['gender']))...

推荐答案

isset vs. !空

FTA:

"isset()检查变量是否具有 值包括(False,0或为空 字符串),但不能为NULL.返回TRUE 如果var存在;否则为假.

"isset() checks if a variable has a value including (False, 0 or empty string), but not NULL. Returns TRUE if var exists; FALSE otherwise.

另一方面,empty()函数 检查变量是否为空 值空字符串,0,NULL或 错误的.如果var有一个 非空且非零值."

On the other hand the empty() function checks if the variable has an empty value empty string, 0, NULL or False. Returns FALSE if var has a non-empty and non-zero value."

这篇关于我应该在哪里使用isset()和!empty()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆