我有一个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
这可读性很差,并且在应该有句点的地方有逗号,并且缺少paren:
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" />';
}
}
相关文章:
- Jquery时间启动计时器,我有一个计时器的代码,但它在页面加载时启动
- Webrtc和socket.io:createanswer()总是有一个错误.为什么?我的代码连接了两个对等体,但其中只
- 是否有一个Javascript函数可以使代码在运行时延迟
- 代码在jsfiddle上运行良好,但有一个函数在网站上不起作用
- 我的javascript代码中有一个奇怪的错误
- 代码有什么问题?它给了我一个运行时错误
- 我正在使用带有 c# 代码的 Asp.net,我有一个带有网格视图的页面,我想使用没有任何 ajax 的 javascr
- 我的Javascript代码中有一个错误
- 是否有一个 Node.js 相当于 PHP 的包含,以便包含的代码可以访问父文件的变量
- 我有一个php文件,里面的代码中有一个错误,我可以'我不知道怎么修?以及将其余代码添加到何处
- 我对用php代码创建的HTML有一个问题
- 用引导程序验证器验证动态TinyMCE是一个错误还是我的代码有问题
- 我创建了一个测试,修改了我在网上找到的代码,但我有一个小问题
- 是否有一个javascript函数将字符转换为&代码;等价的
- 我有一个jQuery代码,其中不透明度随着光标的下降而上升.我该如何反转
- 我的代码有一个意外的语法错误
- 是否有一个(polyfill)代码重置所有继承的CSS属性上的给定元素
- 是否有一个项目可以自动生成JavaScript代理代码来调用ASP..NET MVC动作方法
- 在网站上有一个代码,与alert一起工作,但在满足if条件时不链接到另一个网站
- dojo contentPane,我张贴html代码与href在我的contentPane.html代码有一个脚本,但不