Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php test empty string

Tags:

string

php

I have a bit of php code that I'm not understanding why it is acting as it is. I have a variable called contactId that I want to test to see if it is empty. However even if it is empty it evaluates to true. Code is below. Thanks in advance.

print "*".$contactId."*<br/>";
if($contactId != '')
{
    //queryContact($contactId);
    print "Contact Present<br/>";
}

result returned to screen is:

**

Contact Present

like image 971
jcmitch Avatar asked Nov 07 '11 22:11

jcmitch


1 Answers

If you want to see exactly what your string is, simply use var_dump(), like this, for instance:

var_dump($contactId)

instead of

print "*".$contactId."*<br/>";
like image 174
greg0ire Avatar answered Sep 29 '22 15:09

greg0ire