PHP“意外的$end”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13390268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:19:21  来源:igfitidea点击:

PHP "unexpected $end"

phpsyntax

提问by TeNNoX

i actually checked my code like a hundred times, but i cant find the error:

我实际上检查了我的代码一百次,但我找不到错误:

The error i get: Parse error: syntax error, unexpected $end in /home/tennox/public_html/php/kalender.php on line 46

我得到的错误:解析错误:语法错误,意外的 $end in /home/tennox/public_html/php/kalender.php 第 46 行

I tried to do a function that calculates the easter sunday, in another script without all the other it just works, but in this one not. The other way round the same thing!

我试图做一个计算复活节星期日的函数,在另一个没有其他脚本的脚本中它可以正常工作,但在这个脚本中没有。反过来也是一样的!

<?php
$year = isset($_POST['year']) ? intval($_POST['year']) : date('Y');
$months = array("", "Januar", "Februar", "M?rz", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
$days = array('So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa');
$ostern = getOsterSonntag($year);
?>
<form action="kalender.php" method="POST" target="_self">
<input type="text" name="year" value="<?php echo $year; ?>">
</form>
<table border="1" cellspacing="0">
<?php
for($y=0; $y<32; $y++) {
   echo "<tr height=\"20\">";
   for($x=1; $x<=12; $x++) {
      echo "<td width=\"5%\">";
      $date = strtotime("$y.$x.$year");
      $day = date("d", $date);
      $dayname = $days[date("w", $date)];

      if ($y == 0) {
         echo "<div align=\"center\"><b>$months[$x]</b></div>";
      } elseif ($y < date("t",$date) && !($y == 30 && $x == 2)) {
         if (date("w", $date) == 6 || date("w", $date) == 0)
            echo "<b>";
         echo "$day $dayname";
         if ($date == $ostern)
            echo "(Ostersonntag)";
         if (date("w", $date) == 6 || date("w", $date) == 0)
            echo "</b>";
      } else {
         echo "   -   ";
      }
      echo "</td>";
   }
   echo "</tr>";
}
?>
</table>

<?php
function getOsterSonntag($year) {
   $a = $year % 19;
   $b = $year % 4;
   $c = $year % 7;
   $k = floor($year / 100);
   $p = floor((8*$k + 13) / 25);
   $q = ($k / 4);
   $d = (19*$a + ((15 + $k - $p - $q) % 30)) % 30;
   $e = (2*$b + 4*$c + 6*$d + ((4 + $k - $q) % 7)) % 7;

   $ostern = 22 + $d + $e;
   if ($ostern > 31){
      $ostern -= 31;
      return strtotime("$ostern.4.$year");
   } else
      return strtotime("$ostern.3.$year");
}
?>

回答by tek4granted

That error means that PHP has finished analyzing your code, but you forgot to close a symbol somewhere in your page.Its either you forgot to close a quote, bracket, parenthesis or comma.

该错误意味着 PHP 已完成分析您的代码,但您忘记关闭页面中某处的符号。要么是您忘记关闭引号、括号、括号或逗号。

Hope this helps.

希望这可以帮助。

回答by Niet the Dark Absol

This error usually means that you missed a }. Check all your braces and make sure you have the same number of {as }- a code editor with bracket matching (such as Notepad++) can make this a lot easier.

此错误通常意味着您错过了}. 检查所有的括号,并确保你有相同数量的{作为}-用括号匹配(如记事本++)代码编辑器可以让这个容易得多。

回答by jesanjose

In this part of your code, i think you should add { } for else.

在这部分代码中,我认为您应该为 else 添加 { }。

 $ostern = 22 + $d + $e;
       if ($ostern > 31){
          $ostern -= 31;
          return strtotime("$ostern.4.$year");
       } else
          return strtotime("$ostern.3.$year");

also in this part put { } in this part like this :

同样在这部分把 {} 放在这部分像这样:

if (date("w", $date) == 6 || date("w", $date) == 0) {
      echo "<b>";
      echo "$day $dayname";
}