获取语​​法错误,意外的文件结束错误但似乎无法找到错误

时间:2017-08-18 06:27:15

标签: php

我一直收到一个Parse错误:语法错误,第167行意外的文件结束错误。我已多次浏览此代码,似乎无法找到我所遗漏的内容。我检查了所有括号和陈述,但没有找到任何结果。这个错误可能来自于

#!/usr/local/bin/php -d display_errors=STDOUT
<?php
date_default_timezone_set('America/Los_Angeles'); 


$time_stamp = time();


$disp = $_GET['time_stamp'];
if($disp == "previous")
    $time_stamp -= 43200;
else if($disp == "next")
    $time_stamp += 43200;


$today = date("D, F j, Y, g:i a",$time_stamp);
$start_hour_offset = -3;
$end_hour = 12; 


$table = "event_table";
$field1 = "person";
$field2 = "time";
$field3 = "event_title";
$field4 = "event_message";

try
{

 $db = new SQLite3('dbalexmf14.db');
}
catch (Exception $exception)
{
 echo '<p>There was an error connecting to the
database!</p>';
 if ($db)
 {
 echo $exception->getMessage();
 }

}


/**function get_events($name, $ts){


    $sql = "SELECT * FROM event_table WHERE person = $name, time = $ts || time <= $ts + 3600";
    print "$sql";
    $result = $db->query($sql);
    while($record=$result->fetchArray())
    { $title = $record['event_title'];
    $message = $record['event_message'];
    $a_events= $title. " ". $message;
}**/
function get_hour_string($time_stamp){
$hour = date("g", $time_stamp);
$am_or_pm = date("a",$time_stamp);
return "$hour.00$am_or_pm";
}

print('<?xml version = "1.0" encoding="utf-8"?> ');
 ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>Calendar</title> 

<link rel="stylesheet" type="text/css" href="calendar.css" />

</head>
<body>

<div class="container">
<h1>Bruin Family Schedule for <?php print"$today" ?> </h1>
<table id="event_table">


<?php
// print the header

print " <tr> \n";
print "     <th class='hr_td_'> &nbsp; </th> <th class='table_header'>Alex</th><th class='table_header'>Ashton</th><th class='table_header'>Joshua</th> \n";
print " </tr> \n";


for ($i=0; $i<=$end_hour;++$i)
    {

    $hour_string = get_hour_string($time_stamp + $i*3600);


    if ($i%2 == 0){

        print "<tr class='even_row'>\n";
        print "<td class='hr_td'>$hour_string</td> <td> </td> <td> </td> <td></td>\n";

    }
    if ($i%2 !=0){

        print "<tr class='odd_row'>\n";
        print "<td class='hr_td'>$hour_string</td> <td> </td> <td> </td> <td> </td>\n";

    }

    $sql = "SELECT * FROM event_table WHERE person = 'Alex', time = $ts || time <= $ts + 3600";
    print "$sql";
    $result = $db->query($sql);
    $a_events="";
    $j_events="";
    $ah_events="";
    while($record=$result->fetchArray())
    { $title = $record['event_title'];
    $message = $record['event_message'];
    $a_events= $title. " ". $message;
    }
    $sql = "SELECT * FROM event_table WHERE person = 'Ashton', time = $ts || time <= $ts + 3600";
    print "$sql";
    $result = $db->query($sql);
    while($record=$result->fetchArray())
    { $title = $record['event_title'];
    $message = $record['event_message'];
    $ah_events= $title. " ". $message;
    $sql = "SELECT * FROM event_table WHERE person = 'Joshua', time = $ts || time <= $ts + 3600";
    print "$sql";
    $result = $db->query($sql);
    while($record=$result->fetchArray())
    { $title = $record['event_title'];
    $message = $record['event_message'];
    $j_events= $title. " ". $message;
        //$a_events = get_events("Alex", $time_stamp);
        //$ah_events = get-events("Ashton", $time_stamp);
        //$j_events = get_events("Joshua", $time_stamp);
        print "<td>$a_events</td><td>$j_events</td><td>$ah_events</td>";

        print " </tr> \n";

 ?>

</table>

<div>

<form id="prev" method="get" action="calendar2.php">
    <p>
    <input type="hidden" name="time_stamp" value='previous' />
    <input type="submit" value="Previous"/>
    </p>
</form>

<form id="next" method="get" action="calendar2.php">
    <p>
    <input type="hidden" name="time_stamp" value='next' />
    <input type="submit" value="Next"/>
    </p>
</form>

<form id="today" method="get" action="calendar2.php">
    <p>
    <input type="submit" value="Today"/>
    </p>
</form>
</div>

</div>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

您的代码中似乎没有正确关闭花括号。 试试以下

<?php
date_default_timezone_set('America/Los_Angeles'); 


$time_stamp = time();


$disp = $_GET['time_stamp'];
if($disp == "previous")
    $time_stamp -= 43200;
else if($disp == "next")
    $time_stamp += 43200;


$today = date("D, F j, Y, g:i a",$time_stamp);
$start_hour_offset = -3;
$end_hour = 12; 


$table = "event_table";
$field1 = "person";
$field2 = "time";
$field3 = "event_title";
$field4 = "event_message";

try
{

 $db = new SQLite3('dbalexmf14.db');
}
catch (Exception $exception)
{
 echo '<p>There was an error connecting to the
database!</p>';
 if ($db)
 {
 echo $exception->getMessage();
 }

}


/**function get_events($name, $ts){


    $sql = "SELECT * FROM event_table WHERE person = $name, time = $ts || time <= $ts + 3600";
    print "$sql";
    $result = $db->query($sql);
    while($record=$result->fetchArray())
    { $title = $record['event_title'];
    $message = $record['event_message'];
    $a_events= $title. " ". $message;
}**/
function get_hour_string($time_stamp){
$hour = date("g", $time_stamp);
$am_or_pm = date("a",$time_stamp);
return "$hour.00$am_or_pm";
}

print('<?xml version = "1.0" encoding="utf-8"?> ');
 ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>Calendar</title> 

<link rel="stylesheet" type="text/css" href="calendar.css" />

</head>
<body>

<div class="container">
<h1>Bruin Family Schedule for <?php print"$today" ?> </h1>
<table id="event_table">


<?php


print " <tr> \n";
print "     <th class='hr_td_'> &nbsp; </th> <th class='table_header'>Alex</th><th class='table_header'>Ashton</th><th class='table_header'>Joshua</th> \n";
print " </tr> \n";


for ($i=0; $i<=$end_hour;++$i)
    {

    $hour_string = get_hour_string($time_stamp + $i*3600);


    if ($i%2 == 0){

        print "<tr class='even_row'>\n";
        print "<td class='hr_td'>$hour_string</td> <td> </td> <td> </td> <td></td>\n";

    }
    if ($i%2 !=0){

        print "<tr class='odd_row'>\n";
        print "<td class='hr_td'>$hour_string</td> <td> </td> <td> </td> <td> </td>\n";

    }

    $sql = "SELECT * FROM event_table WHERE person = 'Alex', time = $ts || time <= $ts + 3600";
    print "$sql";
    $result = $db->query($sql);
    $a_events="";
    $j_events="";
    $ah_events="";
    while($record=$result->fetchArray())
    { $title = $record['event_title'];
    $message = $record['event_message'];
    $a_events= $title. " ". $message;
    }
    $sql = "SELECT * FROM event_table WHERE person = 'Ashton', time = $ts || time <= $ts + 3600";
    print "$sql";
    $result = $db->query($sql);
    while($record=$result->fetchArray())
    { $title = $record['event_title'];
    $message = $record['event_message'];
    $ah_events= $title. " ". $message;
    $sql = "SELECT * FROM event_table WHERE person = 'Joshua', time = $ts || time <= $ts + 3600";
    print "$sql";
    $result = $db->query($sql);
    while($record=$result->fetchArray())
    { $title = $record['event_title'];
    $message = $record['event_message'];
    $j_events= $title. " ". $message;
        //$a_events = get_events("Alex", $time_stamp);
        //$ah_events = get-events("Ashton", $time_stamp);
        //$j_events = get_events("Joshua", $time_stamp);
        print "<td>$a_events</td><td>$j_events</td><td>$ah_events</td>";

        print " </tr> \n";
    }
    }
    }
 ?>

</table>

<div>

<form id="prev" method="get" action="calendar2.php">
    <p>
    <input type="hidden" name="time_stamp" value='previous' />
    <input type="submit" value="Previous"/>
    </p>
</form>

<form id="next" method="get" action="calendar2.php">
    <p>
    <input type="hidden" name="time_stamp" value='next' />
    <input type="submit" value="Next"/>
    </p>
</form>

<form id="today" method="get" action="calendar2.php">
    <p>
    <input type="submit" value="Today"/>
    </p>
</form>
</div>

</div>
</body>
</html>