Tuesday, July 15, 2008

"" == 0

An empty string is a length 1 array containing '\0' (which is equal to zero). Javascript automatically casts single length strings to characters and vice versa. '\0' == 0 therefore "" == 0.

To strictly compare, use === operator.

PHP:


if (strpos($S_COMPANY_NAME,"Extreme") === false)

strpos return false if not found, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "". So we have to use === to test it.

No comments: