is_dir and if else outputting syntax error, unexpected T_ELSEIF
I am having some trouble with an if
, else
and is_dir
; I am trying to create a small script that tells me if the input is a folder or a file, I have looked at: http://us2.php.net/manual/en/function.is-dir.php for a few examples, and none of them seemed to resemble mine, I read a bit on if and else 开发者_StackOverflow社区as well, and it looks like I am doing that right so I think I am not using is_dir
the way it is meant to be used. Can someone shed some light on this?
The exact error im getting is:
Parse error: syntax error, unexpected T_ELSE in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\dev\test\php\test.php on line 8
Attempt 1:
<?php
$dir = "/some/random/path/on/the/server";
if (is_dir($dir));
{
echo "Works!";
} elseif(!is_dir($dir)); {
echo "Not good!";
}
?>
Attempt 2:
<?php
$dir = "/some/random/path/on/the/server";
if (! is_dir($dir));
{
echo "Error\n";
} else {
echo "Proceed";
}
?>
Thank you for your help!
Remove semicolon after if
and elseif
statements and you are good to go.
You are closing your conditions with ; - thats your problem. You will have to do this:
<?php
$dir = "/some/random/path/on/the/server";
if (is_dir($dir))
{
echo "Works!";
} elseif( !is_dir($dir) )
{
echo "Not good!";
}
?>
精彩评论