저는 프로그래밍에 익숙하지 않고 스스로 가르쳐야합니다. 그러나, 나는이 프로젝트에서 내가 뭘 잘못하고 있는지 알 수 없다. 이 프로젝트는 나 자신을 위해 PHP에서 바로 가기를 만들기 때문에 많은 코드 라인을 프로그래밍 할 필요가 없습니다. 프로그램 할 때, 때로는 서로 다른 어플리케이션에 대해 동일한 20 줄을 사용합니다. 나는 그것이 많은처럼 보이는 알고내 스크립트가 너무 오래 실행됩니다. if 문이 너무 많이 중첩되어있을 가능성이 있습니까?
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";
}
}
}
:
여기 내 스크립트입니다. 그러나, 나는 프로그래밍 할 때 나의 삶을 더 단순하게 만들려고 노력하고있다.
writeDir(); // at the very least
:
기본적으로 PHP 파일에서 호출이 구문은 OR : writeDir('./', true, 'index.php');
두 번째는 그들에 대한 링크를 대응하는 현재 디렉토리에 파일을 기록하지만, 건너 뜁니다 index.php 파일.
세 번째 인수는 단일 생략 된 페이지 (문자열)이거나 여러 개의 생략 된 페이지의 배열 일 수 있습니다. 또는, 적어도 그것이 내가 성취하려는 것입니다.
물론이 소스 파일에 대한 포함은 내가 사용하는 모든 페이지에서 필요합니다. 이전에는 IT가 작동 할 때 하나의 파일을 제외하고 디렉토리 항목의 목록 만 포맷 할 수있었습니다. 그래서, 파일 배열을 허용하려고했습니다. 이제, 그것은 영원히로드됩니다. 마지막으로 set_time_limit()
함수를 사용하여 스크립트를 종료해야했습니다.
이제 마지막으로 한 가지. set_time_limit()
함수를 사용했을 때 디렉토리 항목이 표시되었지만 어떤 이유로 든 2 개가 ... 어떤 점을 잘못 했습니까?
if 문이 너무 많거나 간과되어 있습니까? 내가 다시 시작해야할까요?
약 5 년 동안 (비 전문적으로) 프로그래밍했기 때문에 나는 그것이 무엇인지 잘 모릅니다. 모든 지침은 크게 감사하겠습니다.
희망 정보 및 세부 정보가 충분합니다.
jdot
P. 이 스크립트를 사용하고자하는 사람이라면 누구든지 환영 할 가치가 있습니다 (사용 가치가있는 경우).
내용은 ($ I = 2; $ i가 <$ directoryList; $ 내가 ++)에 대한 {'- '$ directoryList'가 배열이기 때문에, 올바르게 보이지 않습니다. –
당신은 아파치가 당신에게 맞는지 알고 있습니까? –
코드 재사용에 대해 알고 언어에 대한 복잡한 내용을 익히는 것이 좋습니다. 나는 코드를 재사용하는 아주 좋은 방법 인 클래스와 객체를 살펴보기를 권합니다. –