is_dir 和 if else 输出语法错误,意外的 T_ELSEIF
我在使用 if
、else
和 is_dir
时遇到一些问题;我正在尝试创建一个小脚本,告诉我输入是文件夹还是文件,我查看过: https://www.php.net/manual/en/function.is-dir.php 举几个例子,但它们似乎都不像我的,我也阅读了一点 if 和 else ,看起来我做得对,所以我认为我没有按照它应该使用的方式使用 is_dir
。有人可以解释一下吗?
我得到的确切错误是:
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
尝试 1:
<?php
$dir = "/some/random/path/on/the/server";
if (is_dir($dir));
{
echo "Works!";
} elseif(!is_dir($dir)); {
echo "Not good!";
}
?>
尝试 2:
<?php
$dir = "/some/random/path/on/the/server";
if (! is_dir($dir));
{
echo "Error\n";
} else {
echo "Proceed";
}
?>
谢谢您的帮助!
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: https://www.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 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除
if
和elseif
语句后的分号,就可以开始了。Remove semicolon after
if
andelseif
statements and you are good to go.您正在关闭您的条件; - 那是你的问题。
你必须这样做:
You are closing your conditions with ; - thats your problem.
You will have to do this: