我是一个编程新手,我必须自学。但是,我不知道我在这个项目中做错了什么。这个项目是为我自己,在PHP中做快捷方式,所以我不需要编程这么多行代码;当我编程的时候,有时我在不同的应用程序中使用相同的20行。
下面是我的脚本:function writeDir($directory = null, $link = null, $exception = null) {
if (!isset($directory)) {
$directory = './';
}
if (!isset($link)) {
$link = false;
}
if (!isset($exception)) {
$exception = null;
}
// now...
if ($link==true&&$exception!=null) { // do a link and exception(s)
$directoryList = scandir($directory); // get an array of all directory items
$directoryLength = count($directoryList); // count $directoryList array length
if (is_string($exception)) { // if one (1) exception
for ($i=2; $i<$directoryLength; $i++) { // cycle through all directory items
if ($directoryList[$i] == $exception) { // if we hit that one (1) exception
echo ''; // do nothing
} else {
echo '<a href="' . $directoryList[$i] . '"> ' . $directoryList[$i] . ' </a><br />' . "'n";
}
}
}
if (is_array($exception)) { // if multiple exceptions
$exceptionList = count($exception); // count $exception array length
for ($i=2; $i<$directoryList; $i++) { // cycle through all directory items
for ($j=0; $j<$exceptionList; $j++) { // cycle through all exceptions
if ($directoryList[$i] == $exceptionList[$j]) { // if we hit one of the multiple exceptions
echo ''; // do nothing
} else {
echo '<a href="' . $directoryList[$i] . '"> ' . $directoryList[$i] . ' </a><br />' . "'n";
}
}
}
}
}
if ($link==true&&$exception==null) {
$directoryList = scandir($directory);
$directoryLength = count($directoryList);
for ($i=2; $i<$directoryLength; $i++) {
echo '<a href="' . $directoryList[$i] . '"> ' . $directoryList[$i] . ' </a><br />' . "'n";
}
}
if ($link==false&&$exception!=null) { // do only exception(s) without links
$directoryList = scandir($directory); // get an array of all directory items
$directoryLength = count($directoryList); // count $directoryList array length
if (is_string($exception)) { // if one (1) exception
for ($i=2; $i<$directoryLength; $i++) { // cycle through all directory items
if ($directoryList[$i] == $exception) { // if we hit that one (1) exception
echo ''; // do nothing
} else {
echo $directoryList[$i] . '<br />' . "'n";
}
}
}
if (is_array($exception)) { // if multiple exceptions
$exceptionList = count($exception); // count $exception array length
for ($i=2; $i<$directoryList; $i++) {
for ($j=0; $j<$exceptionList; $j++) {
if ($directoryList[$i] == $exceptionList[$j]) {
echo '';
} else {
echo $directoryList[$i] . '<br />' . "'n";
}
}
}
}
}
if ($link==false&&$exception==null) {
$directoryList = scandir($directory);
$directoryLength = count($directoryList);
for ($i=2; $i<$directoryLength; $i++) {
echo $directoryList[$i] . '<br />' . "'n";
}
}
}
我知道它看起来很多。但是,我想让我的生活在编程时更简单。
基本上,在PHP文件中调用它的语法是: writeDir(); // at the very least
:OR: writeDir('./', true, 'index.php');
第二个写当前目录下的文件和相应的链接,但是跳过index.php文件。
第三个参数可以是单个被省略的页面(作为字符串),也可以是包含多个被省略的页面的数组。或者,至少这是我正在努力实现的。
当然,在我使用它的所有页面上都需要包含这个源文件。以前,当IT工作时,我只能格式化目录项列表,排除一个(1)个文件。因此,我也尝试允许一个文件数组。现在,它永远加载。最后我不得不使用set_time_limit()
函数退出脚本。
现在,最后一件事。当我使用set_time_limit()
函数时,它显示了我的目录项,但由于某种原因,所有项中只有两项…我做错了什么?
是否有太多的if语句,或者我忽略了什么?我应该重新开始吗?
我只编程(非专业)大约5年,所以我真的不知道我在做什么。如有任何指导,将不胜感激。
希望我已经提供了足够的信息和细节。
JDot
注:任何想要使用此脚本的人都非常欢迎(如果它甚至值得使用)。
使用
if($a==1)
{
echo $a;
}
elseif($b==1)
{
echo $b;
}
else
{
echo "c";
}