Using php variables - if variable doesn't exist problem?

Gregory Heinz

New member
Is this correct for php:

if ($var1 && !$var2) { do this }

The part I'm asking about is the exclamation point in front of $var2 -- the if clause is doing this:

if (variable one exists and variable 2 doesn't exist) { do this }


The actual code, if it shows up correctly, is this:

<? if ($meta_description && $meta_keywords) { echo "<meta name=\"description\" content=\"$meta_description\">\n<meta name=\"keywords\" content=\"$meta_keywords\">\n"; }
elsif ($meta_description && !$meta_keywords) { echo "<meta name=\"description\" content=\"$meta_description\">\n";}
elsif (!$meta_description && $meta_keywords) {echo "<meta name=\"keywords\" content=\"$meta_keywords\">\n";}
else { echo "<meta name=\"robots\" content=\"noindex,nofollow\">"; }
?>

I'm getting a 'Parse error: syntax error, unexpected '{' in C:\web\htdocs\php_test\header.php on line 7' which corresponds to this line:

elsif ($meta_description && !$meta_keywords)

and that's the first instance of the if !$variable thing. I don't see where there's a bracket problem unless the ! is causing it.
 
Back
Top