PHP: "unexpected $ end" in the middle of a file
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 weird thing "functions.php" has over 37 lines ... why is it detecting end of file there? I don't think I am missing any parsers or parentheses as each function is only one statement (print statement).
I did a couple of things to try and fix this issue. If I remove the statements in the function definition for print_head () and print_foot (), the error goes away (the rest of the page works fine). If I remove the instructions in one of the functions, I get the same error, only on a different line. If I move function definitions on the page, I get the same error. I even tried to remove parts of the print instruction, but I still get the same error.
EDIT:
"videos / transfer / playlist" is an example file that get_vids () loads. It is a flat txt file with an even number of lines; The odd lines are the name of the video file, and even the lines are the title that goes with the previous file. I have verified that get_vids () works as expected.
EDIT:
This is 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 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;
}
?>
video / transfer / playback
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?
a source to share
It does not detect the final file as such, but the logical end of the executable lines of code.
Make sure the end HEREDOC tokens (ENDHEAD; ENDFOOT;) have no spaces in front of them - at the moment when they are not the first token on the line, they do not register as end HEREDOC tokens, but as an arbitrary string within the limits , so your HEREDOC absorbs more codeblock.
What the only thing that comes to mind is that it php -l <your functions.php>
didn't install any errors for me (but adding a space before ENDHEAD gave me the error you described).
a source to share
I 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 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 php tags around the html you want to display - as you will see above :)
Hope it helps
a source to share