簡體   English   中英

我有一個php文件,並且在里面的代碼中有一個錯誤,我不知道該如何解決? 以及在哪里添加其余代碼

[英]I have a php file and in the code inside i have one error i can't figure out how to fix it ? And where to add the rest of the codes

代碼是:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>    
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>    
  <meta http-equiv="Content-Language" content="en"/>    
  <meta name="viewport" content="width=device-width; height=device-height; initial-scale=1.0"/>   

  <link type="text/css" rel="stylesheet" href="screen.css" media="screen,projection,tv"/>    
  <title>change picture</title>    
</head>

<body>

  <div id="slideCounter"></div>
  <div id="slideShow">
  <?php

  $allowed_types = ['png','jpg','jpeg','gif'];
  $imageDir = 'files/radar-simulation-files';
  /*
    Assumes this .php is being run from the http root on the same
    domain as the desired image files.
  */

  $handle = opendir($imageDir);
  while (($imgPath = readdir($handle)) !== false) if (
    in_array(
        strtolower(pathinfo($imgPath, PATHINFO_EXTENSION)),
        $allowed_types
    ) echo '
    <img src="', $imageDir, '/', $imagePath, '" alt="slide" />';
  closedir($handle);

  ?>
  <!-- #slideShow --></div>

  <script type="text/javascript" src="slideShow.js"></script>

錯誤就在網上:

) echo '

)之后出現意外的回聲

然后,我應該在哪里添加其余代碼? 我有一個javascript函數和一個CSS代碼。 我應該將它們添加到同一php文件中嗎? 如果是這樣,在哪里? html代碼之后? 里面的HTML代碼?

這是Java腳本代碼:

(function(d) {

    // user defines

    var
        swapHours = 0,
        swapMinutes = 0,
        swapSeconds = 5,
        swapTotal = (swapHours * 60 + swapMinutes) * 60 + swapSeconds,
        loopSlideShow = true;

    // some handy helper functions

    function classExists(e, className) {
        return RegExp('(\\s|^)' + className + '(\\s|$)').test(e.className);
    }

    function classAdd(e, className) {
        if (classExists(e, className) return false;
        e.className += (e.className ? ' ' : '') + className;
        return true;
    }

    function classRemove(e, className) {
        if (!classExists(e, className)) return false;
        e.className = e.className.replace(
            new RegExp('(\\s|^)' + n + '(\\s|$)'), ' '
        ) . replace(/^\s+|\s+$/g,'');
        return true;
    }

    function textReplace(e, newtext) {
        if (d.innerText) e.innerText = newText;
            else e.textContent = newText;
    }

    function nodeFirst(e) {
        e = e.firstChild;
        while (e && e.nodeType != 1) e = e.nextSibling;
        return e;
    }

    function nodeLast(e) {
        e = e.lastChild;
        while (e && e.nodeType != 1) e = e.prevSibling;
        return e;
    }

    function nodeNext(e) {
        while (e) if ((e = e.nextSibling).nodeType == 1) return e;
        return null;
    }

    function nodePrev(e) {
        while (e) if ((e = e.prevSibling).nodeType == 1) return e;
        return null;
    }

    // slideShow setup

    var
        slideShow = d.getElementById('slideShow'),
        slideCounter = d.getElementById('slideCounter'),
        firstSlide = nodeFirst(slideShow),
        lastSlide = nodeLast(slideShow),
        currentSlide = firstSlide,
        swapCounter;

    classAdd(slideShow, 'ss_scripted');
    classAdd(currentSlide, 'ss_show');

    // slideShow functions

    function showCounter() {
        textReplace(slideCounter, 
            Math.floor(swapCounter / 3600) + ':' +
            (Math.floor(swapCounter / 60) % 60) + ':' +
            swapCounter % 60
        );
    }

    function resetCounter() {
        swapCounter = swapTotal;
        showCounter();
    }

    function makeSlide(newSlide) {
        classRemove(currentSlide, 'ss_show);
        currentSlide = newSlide;
        classAdd(currentSlide, 'ss_show');
    }

    function nextSlide() { 
        resetCounter();
        var newSlide = nodeNext(currentSlide);
        if (newSlide) makeSlide(newSlide);
            else if (loopSlideShow) makeSlide(firstSlide);
    }

    function prevSlide() {
        resetCounter();
        var newSlide = nodePrev(currentSlide);
        if (newSlide) makeSlide(newSlide);
            else if (loopSlideShow) makeSlide(lastSlide);
    }

    function slideUpdate() {
        if (swapCounter--) showCounter(); else nextSlide();
    }

    function startSlideShow() {
        resetCounter();
        setInterval(slideUpdate, 1000);
    }

    // wait for onload to actually start the countdown 

    if (window.eventListener) w.addEventListener('load', startSlideShow, false);
        else w.addEventListener('onload', startSlideShow);

})(document);

這是css代碼:

.ss_scripted img { display:none; }
.ss_scripted .ss_show { display:block; }

問題是您缺少一個“)”

嘗試

while (($imgPath = readdir($handle)) !== false) if (
    in_array(
        strtolower(pathinfo($imgPath, PATHINFO_EXTENSION)),
        $allowed_types
    )) echo '
    <img src="', $imageDir, '/', $imagePath, '" alt="slide" />';
closedir($handle);

)) echo '首先來自in_array()其次來自if()

希望這可以幫助! :D

這是很差的可讀性,並且您有逗號,應該有句點以及缺少的括號:

while (($imgPath = readdir($handle)) !== false) {
  $needle = strtolower(pathinfo($imgPath, PATHINFO_EXTENSION));
  // YOU WERE MISSING A CLOSING ( ON YOUR IF
  if (in_array($needle, $allowed_types)) {
    // THESE PERIODS WERE COMMAS
    echo '<img src="' . $imageDir . '/' . $imagePath . '" alt="slide" />';
  }
}

closedir($handle);

注意,在這種情況下,我還將使用printf代替echo:

printf('<img src="%s/%s" alt="slide" />', $imgDir, $imgPath);

好像您忘了用括號關閉if語句。

嘗試這個

)) echo '

您在echo之前缺少')',則可以將javascript代碼放在下面的底部:

<script type="text/javascript" src="slideShow.js"></script> 

您忘記了while循環和if語句的花括號。

也許那就是你想要的:

while (($imgPath = readdir($handle)) !== false){
    if (in_array(strtolower(pathinfo($imgPath, PATHINFO_EXTENSION)),$allowed_types)){
      echo '<img src="', $imageDir, '/', $imagePath, '" alt="slide" />';
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM