Connecting Tech Pros Worldwide Help | Site Map

Distinguishing between an empty string and "0"

laredotornado@zipmail.com
Guest
 
Posts: n/a
#1: May 11 '06
Hi,

If I have a $_REQUEST variable that contains either the value "" or
"0", the empty($_REQUEST['myvar']) call returns the same thing -- 1.
How can I distinguish between these values without causing any errors
or warnings (notices)?

I'm using PHP 4. Thanks for the help, - Dave

Rik
Guest
 
Posts: n/a
#2: May 11 '06

re: Distinguishing between an empty string and "0"


laredotornado@zipmail.com wrote:[color=blue]
> Hi,
>
> If I have a $_REQUEST variable that contains either the value "" or
> "0", the empty($_REQUEST['myvar']) call returns the same thing -- 1.
> How can I distinguish between these values without causing any errors
> or warnings (notices)?
>
> I'm using PHP 4. Thanks for the help, - Dave[/color]

$_REQUEST['myvar']===0
or
$_REQUEST['myvar']===''

http://nl2.php.net/manual/en/languag...comparison.php

Grtz,
--
Rik Wasmus


Toby Inkster
Guest
 
Posts: n/a
#3: May 12 '06

re: Distinguishing between an empty string and "0"


laredotornado@zipmail.com wrote:
[color=blue]
> If I have a $_REQUEST variable that contains either the value "" or
> "0", the empty($_REQUEST['myvar']) call returns the same thing -- 1.[/color]

if (strlen($_REQUEST['myvar']))
{
// not empty
}

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Closed Thread