PHP:“意外的 $end”在文件的中间

发布于 2024-08-31 02:41:00 字数 4506 浏览 8 评论 0原文

当我尝试运行此页面(video.php)时,出现以下错误:

解析错误:语法错误,/base/path/masked/inc/functions.php 第 37 行出现意外的 $end

的是“functions.php”超过 37 行...为什么它检测到文件结尾那里?我不认为我缺少任何括号或方括号,因为每个函数只有一个语句(一条打印语句)长。

我已经做了几件事来尝试解决这个问题。如果我删除 print_head() 和 print_foot() 函数定义中的语句,错误就会消失(页面的其余部分工作正常)。如果我删除任一函数中的语句,我会得到相同的错误,只是在不同的行上。如果我在页面上移动函数定义,则会收到相同的错误。我什至尝试删除部分打印语句,但仍然遇到相同的错误。

编辑:
“videos/transfer/playlist”是 get_vids() 加载的示例文件。这是一个具有偶数行的平面 txt 文件;奇数行是视频文件的名称,偶数行是与前一个文件相关的标题。我已经测试过以确保 get_vids() 按预期工作。

编辑:
这是当我尝试从命令行运行所有内容时得到的结果:

$ php -l video.php
No syntax errors detected in video.php
$ php video.php

Parse error: syntax error, unexpected $end in /home/nova20/http-dir/orientation/inc/functions.php on line 37
$ php -l inc/functions.php

Parse error: syntax error, unexpected $end in inc/functions.php on line 37
Errors parsing inc/functions.php

这是我的代码:

video.php:

<?php
include('inc/functions.php');

$type=$_GET['type'];
if($type == '') {
    $type = 'transfer';
}

$vidno = $_GET['vid'];
if($vidno == '') {
    $vidno = 1;
}

$vidindex = $vidno - 1;

$videos = get_vids($type);

$filename = $videos[$vidindex]['file'];
$title = $videos[$vidindex]['title'];
$basedir = "videos/$type";
$vidfile = "$basedir/$filename";

if($vidfile != '') {
    $extra = '<script src="/flowplayer/flowplayer-3.1.4.min.js"></script>';
    print_head($title, $extra);

    print <<<ENDHTML
<p>
<a
    href='$vidfile'
    style="display:block;width:640px;height:498px;"
    id="player"
></a>
</p>

<p id="contlink" style="display:none">
<a href="done.php?type=$type&vid=$vidno">Click Here to continue</a>
</p>

<script language="JavaScript">
    flowplayer(
        "player",
        "/flowplayer/flowplayer-3.1.5.swf",
        {
            clip: {
                onFinish: function(){
                    //window.location = "done.php";
                    //alert('done!');
                    document.getElementById('contlink').style.display = "block";
                }
            },
            plugins: {
                controls: {
                    play:true,
                    volume:true,
                    mute:true,
                    time:true,
                    stop:true,
                    fullscreen:true,
                    scrubber:false
                }
            }
        }
    );
</script>
ENDHTML;

    print_foot();
} else {
    print_head('OOPS!');

    print <<<ENDERROR
<h1>OOPS!</h1>
<p>
It looks like there's no video here.  <a onclick="history.go(-1);return false;" href="#">Go back</a> and try again.
</p>
ENDERROR;

    print_foot();
}
?>

inc/functions.php(我认为问题所在):

<?php
function get_vids($type) {
    $base = "videos/$type";
    $playlist = "$base/playlist";

    $vidinfo = file($playlist);

    $videos = array();

    for($i = 0; $i < count($vidinfo); $i += 2) {
        $filename = trim($vidinfo[$i]);
        $title = trim($vidinfo[$i+1]);

        if($filename != '') {
            $index = $i / 2;
            $video['file'] = $filename;
            $video['title'] = $title;

            $videos[$index] = $video;
        }
    }

    return($videos);
}

function print_head($title, $extra = '') {
    print <<<ENDHEAD
<html>
<head>
<title>$title</title>
$extra
</head>
<body>

ENDHEAD;
}

function print_foot() {
    print <<<ENDFOOT

</body>
</html>
ENDFOOT;
}
?>

videos/transfer/playlist

1.flv
Introduction
2.flv
Why am I doing this?
3.flv
What can I access with RAIN?
4.flv
How do I access my RAIN Account?
5.flv
How do I Check my registration status?
6.flv
Evaluating transfer credit
7.flv
Transferable degrees
8.flv
Physical Education and History
9.flv
Regents exemptions
10.flv
Academic status
11.flv
How to find my academic advisor?
12.flv
Is Financial Aid available?
13.flv
How do I check my financial aid status?
14.flv
How do I transfer my hope scholarship?
15.flv
Payment information
16.flv
Student Services (Part 1)
17.flv
Student Services (Part 2)
18.flv
Student Services (Part 3)
19.flv
Campus Bookstore
20.flv
Where can I eat on Campus?
21.flv
Where can I live on Campus?
22.flv
How do I register for Parking?
23.flv
Still Have questions?

When I try to run this page (video.php), I get the following error:

Parse error: syntax error, unexpected $end in /base/path/masked/inc/functions.php on line 37

The strange thing is "functions.php" has more than 37 lines... why is it detecting an end of file there? I don't think I'm missing any parens or brackets since each function is only one statement (a print statement) long.

I've done several things to try and fix the problem. If I remove the statements in the function definition for both print_head() and print_foot(), the error goes away (the rest of the page works fine). If I remove statements in either one of the functions, I get the same error, just on a different line. If I move the function definitions around on the page, I get the same error. I've even tried removing parts of the print statement, but I still get the same error.

EDIT:
'videos/transfer/playlist' is an example file that get_vids() loads. It's a flat txt file with an even number of lines; odd lines are the name of a video file, and even lines are the title that go with the preceding file. I've tested to make sure get_vids() works as expected.

EDIT:
Here's what I get when I try to run everything from the command line:

$ php -l video.php
No syntax errors detected in video.php
$ php video.php

Parse error: syntax error, unexpected $end in /home/nova20/http-dir/orientation/inc/functions.php on line 37
$ php -l inc/functions.php

Parse error: syntax error, unexpected $end in inc/functions.php on line 37
Errors parsing inc/functions.php

Here's my code:

video.php:

<?php
include('inc/functions.php');

$type=$_GET['type'];
if($type == '') {
    $type = 'transfer';
}

$vidno = $_GET['vid'];
if($vidno == '') {
    $vidno = 1;
}

$vidindex = $vidno - 1;

$videos = get_vids($type);

$filename = $videos[$vidindex]['file'];
$title = $videos[$vidindex]['title'];
$basedir = "videos/$type";
$vidfile = "$basedir/$filename";

if($vidfile != '') {
    $extra = '<script src="/flowplayer/flowplayer-3.1.4.min.js"></script>';
    print_head($title, $extra);

    print <<<ENDHTML
<p>
<a
    href='$vidfile'
    style="display:block;width:640px;height:498px;"
    id="player"
></a>
</p>

<p id="contlink" style="display:none">
<a href="done.php?type=$type&vid=$vidno">Click Here to continue</a>
</p>

<script language="JavaScript">
    flowplayer(
        "player",
        "/flowplayer/flowplayer-3.1.5.swf",
        {
            clip: {
                onFinish: function(){
                    //window.location = "done.php";
                    //alert('done!');
                    document.getElementById('contlink').style.display = "block";
                }
            },
            plugins: {
                controls: {
                    play:true,
                    volume:true,
                    mute:true,
                    time:true,
                    stop:true,
                    fullscreen:true,
                    scrubber:false
                }
            }
        }
    );
</script>
ENDHTML;

    print_foot();
} else {
    print_head('OOPS!');

    print <<<ENDERROR
<h1>OOPS!</h1>
<p>
It looks like there's no video here.  <a onclick="history.go(-1);return false;" href="#">Go back</a> and try again.
</p>
ENDERROR;

    print_foot();
}
?>

inc/functions.php (where I think the problem is):

<?php
function get_vids($type) {
    $base = "videos/$type";
    $playlist = "$base/playlist";

    $vidinfo = file($playlist);

    $videos = array();

    for($i = 0; $i < count($vidinfo); $i += 2) {
        $filename = trim($vidinfo[$i]);
        $title = trim($vidinfo[$i+1]);

        if($filename != '') {
            $index = $i / 2;
            $video['file'] = $filename;
            $video['title'] = $title;

            $videos[$index] = $video;
        }
    }

    return($videos);
}

function print_head($title, $extra = '') {
    print <<<ENDHEAD
<html>
<head>
<title>$title</title>
$extra
</head>
<body>

ENDHEAD;
}

function print_foot() {
    print <<<ENDFOOT

</body>
</html>
ENDFOOT;
}
?>

videos/transfer/playlist

1.flv
Introduction
2.flv
Why am I doing this?
3.flv
What can I access with RAIN?
4.flv
How do I access my RAIN Account?
5.flv
How do I Check my registration status?
6.flv
Evaluating transfer credit
7.flv
Transferable degrees
8.flv
Physical Education and History
9.flv
Regents exemptions
10.flv
Academic status
11.flv
How to find my academic advisor?
12.flv
Is Financial Aid available?
13.flv
How do I check my financial aid status?
14.flv
How do I transfer my hope scholarship?
15.flv
Payment information
16.flv
Student Services (Part 1)
17.flv
Student Services (Part 2)
18.flv
Student Services (Part 3)
19.flv
Campus Bookstore
20.flv
Where can I eat on Campus?
21.flv
Where can I live on Campus?
22.flv
How do I register for Parking?
23.flv
Still Have questions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

捎一片雪花 2024-09-07 02:41:00

它本身并不是检测文件结尾,而是检测可执行代码行的逻辑结尾。

确保您的 HEREDOC 结束标记(ENDHEAD; 和 ENDFOOT;)前面没有空格 - 当它们不是线路上的第一个标记时,它们不会注册为 HEREDOC 结束标记,而是注册为 中的任意字符串,因此您的 HEREDOC 会吃掉更多的代码块。

这是唯一想到的事情 - php -l <​​yourfunctions.php> 没有给我带来任何错误(但在 ENDHEAD 之前添加一个空格;给了我你所描述的错误)。

It's not detecting an end-of-file, per se, but a logical end of the executable lines of code.

Make sure your HEREDOC end tokens (ENDHEAD; and ENDFOOT;) have no spaces before them - the moment they're not the first token on the line, they don't register as HEREDOC end tokens but as an arbitrary string within, so your HEREDOC eats up more of the codeblock.

That's the only thing that comes to mind - php -l <your functions.php> netted me no errors (but adding a space before ENDHEAD; gave me the error you described).

厌倦 2024-09-07 02:41:00

我已经为你修复了代码:

    <?php
include('inc/functions.php');

$type=$_GET['type'];
if($type == '') {
    $type = 'transfer';
}

$vidno = $_GET['vid'];
if($vidno == '') {
    $vidno = 1;
}

$vidindex = $vidno - 1;

$videos = get_vids($type);

$filename = $videos[$vidindex]['file'];
$title = $videos[$vidindex]['title'];
$basedir = "videos/$type";
$vidfile = "$basedir/$filename";

if($vidfile != '') {
    $extra = '<script src="/flowplayer/flowplayer-3.1.4.min.js"></script>';
    print_head($title, $extra);

    ?>
<p>
<a
    href='<?=$vidfile;?>'
    style="display:block;width:640px;height:498px;"
    id="player"
></a>
</p>

<p id="contlink" style="display:none">
<a href="done.php?type=<?=$type;?>&vid=<?=$vidno;?>">Click Here to continue</a>
</p>

<script language="JavaScript">
    flowplayer(
        "player",
        "/flowplayer/flowplayer-3.1.5.swf",
        {
            clip: {
                onFinish: function(){
                    //window.location = "done.php";
                    //alert('done!');
                    document.getElementById('contlink').style.display = "block";
                }
            },
            plugins: {
                controls: {
                    play:true,
                    volume:true,
                    mute:true,
                    time:true,
                    stop:true,
                    fullscreen:true,
                    scrubber:false
                }
            }
        }
    );
</script>
<?php

    print_foot();
} else {
    print_head('OOPS!');

?>
<h1>OOPS!</h1>
<p>
It looks like there's no video here.  <a onclick="history.go(-1);return false;" href="#">Go back</a> and try again.
</p>
<?php

    print_foot();
}
?>

你可以打开和关闭你想要显示的 html 周围的 php 标签 - 正如你在上面看到的:)

希望有帮助

I've fixed the code for you:

    <?php
include('inc/functions.php');

$type=$_GET['type'];
if($type == '') {
    $type = 'transfer';
}

$vidno = $_GET['vid'];
if($vidno == '') {
    $vidno = 1;
}

$vidindex = $vidno - 1;

$videos = get_vids($type);

$filename = $videos[$vidindex]['file'];
$title = $videos[$vidindex]['title'];
$basedir = "videos/$type";
$vidfile = "$basedir/$filename";

if($vidfile != '') {
    $extra = '<script src="/flowplayer/flowplayer-3.1.4.min.js"></script>';
    print_head($title, $extra);

    ?>
<p>
<a
    href='<?=$vidfile;?>'
    style="display:block;width:640px;height:498px;"
    id="player"
></a>
</p>

<p id="contlink" style="display:none">
<a href="done.php?type=<?=$type;?>&vid=<?=$vidno;?>">Click Here to continue</a>
</p>

<script language="JavaScript">
    flowplayer(
        "player",
        "/flowplayer/flowplayer-3.1.5.swf",
        {
            clip: {
                onFinish: function(){
                    //window.location = "done.php";
                    //alert('done!');
                    document.getElementById('contlink').style.display = "block";
                }
            },
            plugins: {
                controls: {
                    play:true,
                    volume:true,
                    mute:true,
                    time:true,
                    stop:true,
                    fullscreen:true,
                    scrubber:false
                }
            }
        }
    );
</script>
<?php

    print_foot();
} else {
    print_head('OOPS!');

?>
<h1>OOPS!</h1>
<p>
It looks like there's no video here.  <a onclick="history.go(-1);return false;" href="#">Go back</a> and try again.
</p>
<?php

    print_foot();
}
?>

You can just open and close the php tags around the html that you want to display - as you will see above :)

Hope that helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文