Jump to content

Archived

This topic is now archived and is closed to further replies.

Allen4172

Check to see if value is NULL

Recommended Posts

I've tried a couple of things and can't seem to get it to work properly.

I'm attempting to check if a value is NULL. I've tried things like:

[code]

if($variable$ == NULL) {
   $php_var = 0;}
[/code]

The variable isn't from PHP, its from a CMS system, that uses its variables as $something$. With this system, if nothing is typed in, its just blank spaces and the php would see:

[code]
if(     == NULL){
   $php_var = 0;}

[/code]

I'm trying to make it to where, if nothing was entered in, and the script sees the blank, then it would auto put it as 0. Any help or ideas would be appreciated. :)

Share this post


Link to post
Share on other sites
im not sure i follow, but in a lack of responce - her is a suggestion on setting variables if they don't exist or is false (0):
[code]
if(!$var)
{
$var = "whatever";
}
[/code]

Share this post


Link to post
Share on other sites
Thanks for the reply.

In that scenerio when that field is false ($example$) the php sees:

[code]
if(!)
{
$var = "whatever";
}
[/code]

It then gives an error of [b]Parse error: parse error, unexpected ')'[/b]

Share this post


Link to post
Share on other sites
[code]
$var = '$variable$';
if (strlen($var) == 0)
{
    $var = 0;
}
[/code]

Share this post


Link to post
Share on other sites
[a href=\"http://www.php.net/manual/en/function.is-null.php\" target=\"_blank\"]http://www.php.net/manual/en/function.is-null.php[/a]
....

Orio.

Share this post


Link to post
Share on other sites
[!--quoteo(post=375438:date=May 19 2006, 11:24 PM:name=Dave K.)--][div class=\'quotetop\']QUOTE(Dave K. @ May 19 2006, 11:24 PM) [snapback]375438[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]
$var = '$variable$';
if (strlen($var) == 0)
{
    $var = 0;
}
[/code]
[/quote]

Thanks Dave, that is exactly what I needed and it now works :) I tried something similar earlier, but I didn't put the single quotes around $variable$ from above.

Share this post


Link to post
Share on other sites
There is always empty() as per [a href=\"http://us3.php.net/empty\" target=\"_blank\"]empty()[/a] in the PHP Manual.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.