如何验证字符串为空


How to verify string is empty

我从FORM中获取VIN号,但有时用户不输入任何内容,只发送空白表单。

我需要调试它,所以我添加了一些类似的东西:

   if (isset($this->vin)) 
    {
    //CODE HERE
    } 

问题是我的数据库中仍然有空字符串。所以我var_dump($this->vin),如果用户不输入vin,var dump说:string(0)"

因此,我将我的声明编辑为:

if (isset($this->vin) || $this->vin != "")        
{
//CODE HERE
}

但还是无济于事,伙计们,有没有暗示我该怎么解决这个问题?感谢

$this->vin总是被设置的(假设你从post设置它,所以它存在)

尝试:

if(!empty(trim($this->vin)))
{//check if empty even if spaces are introduced
}

您可以使用!空表达式

if ( !empty($this->vin) ) {
//Code here
}

http://php.net/manual/en/function.empty.php